V. 01 – 12/04/2018 5 ©Velleman nv
if(val==LOW) //If this value is LOW:
{ digitalWrite(ledpin,LOW);} // then ledpin (the led on digital line 13) is also LOW (off)
else
{ digitalWrite(ledpin,HIGH);} // in the other case (ledpin is not low) switch ON the LED on D13
}
void loop()
{
for (int i = BASE; i < BASE + NUM; i ++)
{
digitalWrite(i, LOW); //Switch OFF Digital lines 10 to 13 one by one
delay(200); // wait 0,2 seconds
}
for (int i = BASE; i < BASE + NUM; i ++)
{
digitalWrite(i, HIGH); //Switch ON Digital lines 10 to 13 one by one
delay(200); //wait 0,2 seconds
}
}
//*******************************************************************************
// VMA209 - LED START-STOP BY PUSH BUTTON EXAMPLE
// function : press S1, LED D1 will light -- press S1 again, LED D1 will switch off
// programmed on:Arduino IDE-----------------------------------------
// compatible with Arduino UNO, MEGA
//*******************************************************************************
#define LED 13 // LED is on digital 13, another value between line 10 and 13 can be chosen ! Just give it a
try !
#define KEY A1 // we choose one of the available push buttons which are on A1, A2 or A3. In this case we
choose A1 but You can try another one
int KEY_NUM = 0;
void setup()
{
pinMode(LED,OUTPUT); // initialize LED (D13) as output
pinMode(KEY,INPUT_PULLUP); //initialize KEY (analog pin A1) as an input with the internal
pull-up resistor enabled
}
void loop()
{
ScanKey(); // check if there is a key pressed (see void ScanKey)
if(KEY_NUM == 1) // key 1 pressed
{
digitalWrite(LED,!digitalRead(LED));// Inverte the LED status
}
}