I think the reason is the arduino support abundant examples and functions.
Nervertheless I don't know ATmega, I could led on/off easily.
This is demo video and picture.
To experiment my case, you need arduino board, resistance 220om and led.
And to setup your arduino is explained very well on the homepage.
http://arduino.cc/en/Guide/HomePage
http://arduino.cc/en/Guide/Windows
Thank you.
source code
/* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */ // Pin 13 has an LED connected on most Arduino boards. // give it a name: int led = 13; int mode=0; int order=1; int count=0; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); pinMode(led-1,OUTPUT); pinMode(led-2,OUTPUT); pinMode(led-3,OUTPUT); pinMode(led-4,OUTPUT); } // the loop routine runs over and over again forever: void loop() { if(mode == 0) count = count+1; else count = count-1; for(int i=0; i< 5 i=i+1) { if(count%5 == i) digitalWrite(led-i, HIGH); // turn the LED on (HIGH is the voltage level) else digitalWrite(led-i, LOW); // turn the LED on (HIGH is the voltage level) } delay(200); if(mode == 0) { if(count == 50) mode=1; }else{ if(count == 0) mode=0; } }
No comments:
Post a Comment