first commit
This commit is contained in:
79
src/main.cpp
Normal file
79
src/main.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#define LED1 PB14
|
||||
#define LED2 PB15
|
||||
#define LED3 PA8
|
||||
#define BUTTON PA0
|
||||
|
||||
#define BUTTONDELAY 500
|
||||
|
||||
|
||||
uint8_t patternIndex = 0;
|
||||
unsigned long buttontimer = 0;
|
||||
bool buttonFlag = false;
|
||||
bool patternFlag = false;
|
||||
|
||||
|
||||
uint8_t ledpattern[5][3] = {
|
||||
{1,0,0},
|
||||
{0,0,1},
|
||||
{0,1,0},
|
||||
{0,1,0},
|
||||
{0,0,1}
|
||||
};
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED1, OUTPUT);
|
||||
pinMode(LED2, OUTPUT);
|
||||
pinMode(LED3, OUTPUT);
|
||||
pinMode(BUTTON, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
//debounce button
|
||||
if(!digitalRead(BUTTON))
|
||||
{
|
||||
if(!buttonFlag)
|
||||
{
|
||||
//button not detected jet, check timer
|
||||
if(currentMillis - buttontimer >= BUTTONDELAY)
|
||||
{
|
||||
buttonFlag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//button is not pressed, keep updating the timer
|
||||
buttonFlag = false;
|
||||
patternFlag = false;
|
||||
buttontimer = millis();
|
||||
}
|
||||
|
||||
if(buttonFlag)
|
||||
{
|
||||
if(!patternFlag)
|
||||
{
|
||||
patternIndex++;
|
||||
if(patternIndex > 5)
|
||||
{
|
||||
patternIndex = 0;
|
||||
}
|
||||
patternFlag = true;
|
||||
}
|
||||
//write pattern to the LEDs
|
||||
digitalWrite(LED1,!ledpattern[patternIndex][0]);
|
||||
digitalWrite(LED2,!ledpattern[patternIndex][1]);
|
||||
digitalWrite(LED3,!ledpattern[patternIndex][2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(LED1,1);
|
||||
digitalWrite(LED2,1);
|
||||
digitalWrite(LED3,1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user