I tried to make it very simple.
Here you can see minimum hardware used:
Arduino UNO
Arduino USB cable
White LED
Laptop with Arduino IDE
I chose Arduino UNO from the drop down menu.
Then opened Blink example.
And then I got the code that reads serial monitor to control LED and changed it to control blink rate.
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
*/
int led = 8;
int MyDelay = 50 ;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Serial.begin(9600);
while (!Serial);
Serial.println("Input 1 to increase delay on and 2 to decrease delay ");
}
void change_rate() {
if (Serial.available())
{
int state = Serial.parseInt();
if (state == 1)
{
if(MyDelay < 1000 )
MyDelay = MyDelay + 10 ;
Serial.println("Command completed delay increases");
}
if (state == 2)
{
if(MyDelay > 0 )
MyDelay = MyDelay - 10 ;
Serial.println("Command completed delay decreases");
}
}
}
// the loop routine runs over and over again forever:
void loop() {
change_rate();
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(10); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(MyDelay); // wait for a second
}
Check our books on Amazon we created on our way to find happiness.
No comments:
Post a Comment