Thursday, June 17, 2010

Posting Settings Design Monetize View Blog New Post Edit Posts Edit Pages



By using the code keep LED on after button is released I was able to add a photo sensor with the push button to achieve what I wanted. The only issues I am having is not being able to control motors on this code and inverting the sensor to turn on when lights are off versus when they are on.

www.makezine.com/getstartedarduino


Within the next week hopefully the code can be redone to figure out the issues...

// Example 03A: Turn on LED when the button is pressed  // and keep it on after it is released  // // Copy and paste this example into an empty Arduino sketch  #define LED  13  // the pin for the LED  #define BUTTON 7 // the input pin where the                  // pushbutton is connected int val = 0;     // val will be used to store the state                  // of the input pin  int state = 0;   // 0 = LED off while 1 = LED on   void setup() {    pinMode(LED, OUTPUT);   // tell Arduino LED is an output    pinMode(BUTTON, INPUT); // and BUTTON is an input  }    void loop() {    val = digitalRead(BUTTON); // read input value and store it     // check if the input is HIGH (button pressed)    // and change the state    if (val == HIGH) {      state = 1 - state;    }      if (state == 1) {           digitalWrite(LED, HIGH); // turn LED ON    } else {      digitalWrite(LED, LOW);    }  } 

Once again with this code my LED's are running 010101010101010 on and off constantly... I am only achieving half brightness.


No comments:

Post a Comment