Rik's Ramblings

Thursday, October 18, 2007

Real Engineering

Yeah! Got myself an Arduino board (http://www.arduino.cc/) from Make

Now I can do some real engineering!

Sagar Robotics here we come.

Here's my first app: it's C++ don't you know

---

/*
* Blink
*
* The basic Arduino example. Turns on an LED on for one second,
* then off for one second, and so on... We use pin 13 because,
* depending on your Arduino board, it has either a built-in LED
* or a built-in resistor so that you need only an LED.
*
* http://www.arduino.cc/en/Tutorial/Blink

*/

int ledPin = 13; // LED connected to digital pin 13

void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}

void pwmed(int mark, int seconds)
{
int showTens = seconds *100;
int space = 0;

if (mark <= 0) { digitalWrite(ledPin, LOW); delay(10*showTens); } else if (mark < 10) { space = 10-mark;

while( showTens )
{
digitalWrite(ledPin, HIGH);
delay(mark);
digitalWrite(ledPin, LOW);
delay(space);

--showTens;
}
}
else
{
digitalWrite(ledPin, HIGH);
delay(10*showTens);
}

}



/**
* A modified version of the basic example "blink" that
* uses PWM (pulse width modulation) to make the brightness
* of the LED change.
*/
void loop() // run over and over again
{

// Ramp
pwmed(0,1);
pwmed(1,1);
pwmed(2,1);
pwmed(3,1);
pwmed(4,1);
pwmed(5,1);
pwmed(6,1);
pwmed(7,1);
pwmed(8,1);
pwmed(9,1);
pwmed(10,1);

// Half, Off, On!
pwmed(5,1);
pwmed(0,5);
pwmed(10,5);

}

0 Comments:

Post a Comment



<< Home