Saturday, March 20, 2010

Push on Push off

I'll test the code in the morning.



#define LED 13
#define BUTTON 7

int val = 0;
int state = 0;

void setup {
pinMode(LED, OUTPUT)
pinMode(BUTTON, INPUT)
}

void loop {
val = digitalRead(BUTTON);

if (val == HIGH && state == 0) {
digitalWrite(LED, HIGH);
pause(500);
state = 1;
}
if ((val == HIGH) && (state == 1)){
digitalWrite(LED, LOW);
pause(500);
state = 0;
}
}

Pushing a button

Next up is pushing a button to turn on a light. I'm going to modify it to a push on - push off setup when I'm done.

#define LED 13
#define BUTTON 7

int val = 0;

void setup {
   pinMode(LED, OUTPUT)
   pinMode(BUTTON, INPUT)
}

void loop {
  val = digitalRead(BUTTON);
  if (val == HIGH) {
     digitalWrite(LED, HIGH);
  }else{
     digitalWrite(LED, LOW);
  }
}

Thursday, March 18, 2010

Driving a servo

I jumped right into a servo driving program. All it does is send the servo all the way to one end of it's rotation, wait, send it all the way to the other end of it's rotation, wait and repeat. Not much, but it's a start.

Arduino - first sketch

Of course I started with the blink one LED on pin 13 standard.

//Example 01 : Blinking LED

#define LED 13

void setup()
{
pinMode(LED, OUTPUT);
}

void loop()
{
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
}