Go Down

Topic: My First Arduino (Read 651 times) previous topic - next topic

Anthony

Nov 21, 2007, 12:54 am Last Edit: Nov 21, 2007, 03:51 am by Anthony Reason: 1
Actually, it's a Freeduino based off the Arduino, but it's essentially the same and it works with the Arduino drivers and dev program.  Now that I got that over with...

Anyways, I have finished my first program.  It's the flash sketch, but I made some very simple modifications; it will only flash 5 times, and it uses Serial to print to the computer that it has flashed 5 times.  The LED I used is a flashing LED, so it flashes for a second instead of staying solid.  I have a good knowledge of Java and C programming, and I thought I should give this a try to learn more things about the electronics side.

Check it out; I hope to do more stuff whenever I get the time.


Code: [Select]

#define ledPin 13  // LED connected to digital pin 13
#define FLASHES 5  // How many times the LED will flash

void setup()
{
 Serial.begin(9600);           // Sets the baud rate to send serial data to my computer
 pinMode(ledPin, OUTPUT);      // sets the digital pin as output
 
 int i;
 for (i = 0; i < FLASHES; i++)
 {
   digitalWrite(ledPin, HIGH);   // sets the LED on
   delay(1000);                  // waits for a second
   digitalWrite(ledPin, LOW);    // sets the LED off
   delay(1000);                  // waits for a second
   Serial.println(i+1,DEC);      // print the amount of times it has flashed so far
 }
 
 //Print a sentence stating how many times it has flashed
 Serial.print("I am done flashing ");
 Serial.print(FLASHES,DEC);
 Serial.print(" times.");  
}

/*
 I'm not using the loop function below because I only want the program to run the code once :(
*/
void loop(){}

Edit:  After posting this, I later found a red LED and it worked like it should :D
Buy a breadboard; it's worth it!

Go Up