Pages: [1]   Go Down
Author Topic: My First Arduino  (Read 628 times)
0 Members and 1 Guest are viewing this topic.
Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino & Freeduino rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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 smiley-grin
« Last Edit: November 20, 2007, 09:51:37 pm by Anthony » Logged

Buy a breadboard; it's worth it!

Pages: [1]   Go Up
Jump to: