Hello everyone. I'm new to the world or arduino and am playing around with the blink sketch.
I am for now only using the on board LED on the UNO. I can not get this sketch to compile. What am I doing wrong or leaving out?
I feel like it should work. Is this one of the problems caused by using delay in place of unsigned long?
Thank you in advance for any help you can provide.
This is my modified code:
/*
Blink
Turns an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
the correct LED pin independent of which board is used.
If you want to know what pin the on-board LED is connected to on your Arduino
model, check the Technical Specs of your board at:
modified 8 May 2014
by Scott Fitzgerald
modified 2 Sep 2016
by Arturo Guadalupi
modified 8 Sep 2016
by Colby Newman
This example code is in the public domain.
*/
#define TIME_SCALE_ONE_ENABLE_PIN 2 // set this pin high to enable time scale one second on/five seconds off
#define TIME_SCALE_TWO_ENABLE_PIN 3 // Set this pin high to enable time scale five seconds on/one second off
#define TIME_SCALE_THREE_ENABLE_PIN 4 // set this pin high to enable time scale one minute on/off
#define TIME_SCALE_FOUR_ENABLE_PIN 5 // set this pin high to enable time scale one minute on and five minutes off
#define TIME_SCALE_FIVE_ENABLE_PIN 6 // set this pin high to enable time sclae five minutes on and one minute off
int val1 = 1000; // cycle time of one second on
int val2 = 5000; // cycle time of five seconds off
int val3 = 5000; // cycle time of five seconds on
int val4 = 1000; // cycle time of one second off
int val5 = 60000; // cycle time of one minute on
int val6 = 60000; // cycle time of one minute off
int val7 = 60000; // cycle time of one minute on
int val8 = 300000; // cycle time of five minutes off
int val9 = 300000; // cycle time of five minutes on
int val10 = 60000; // cycle time of one minute off
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
pinMode(TIME_SCALE_ONE_ENABLE_PIN, INPUT);
pinMode(TIME_SCALE_TWO_ENABLE_PIN, INPUT);
pinMode(TIME_SCALE_THREE_ENABLE_PIN, INPUT);
pinMode(TIME_SCALE_FOUR_ENABLE_PIN, INPUT);
pinMode(TIME_SCALE_FIVE_ENABLE_PIN, INPUT);
}
// the loop function runs over and over again forever
void loop() {
if (digitalRead(2) == HIGH){
delay = val1;
delay = val2;
}
else if (digitalRead(3) == HIGH){
delay = val3;
delay = val4;
}
else if (digitalRead(4) == HIGH){
delay = val5;
delay = val6;
}
else if (digitalRead(5) == HIGH){
delay = val7;
delay = val8;
}
else if (digitalRead(6) == HIGH){
delay = val9;
delay = val10;
}
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(val1); // Adjust on time as needed. One second is equal to one thousand
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(val2); // wait for a second
}