Created
January 16, 2017 00:23
-
-
Save helloCaller/26a02f1aeffca184dcc6d063ef2e7528 to your computer and use it in GitHub Desktop.
mutilplesAtelier2GentleReminder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Every Button click increases the amount of delay by 30s | |
* before sound occurs. Alarm is initiated after a button press has been registered | |
* | |
* | |
* note: -not the best debouncing used for button presses | |
* -no delay() has been used in case other things need to happen at the same time | |
* | |
*/ | |
const int buzzerPin = 9; //buzzerPin on pin 9 | |
const int buttonPin = 5; //button on pin 5 | |
int buttonState; //hold state HIGH or LOW of button | |
unsigned long currentTime; //store time from when controller has started | |
unsigned long previousTime = 0; // previous time to use instead of delay | |
unsigned long offsetTime; // start of time when button is pressed | |
unsigned long timeReset; //the result of currentTime - offsetTime | |
unsigned long buttonPressTime = 0; //delay to only check on button every so often | |
bool buttonPressed = false; // has a buttonPress been registered | |
unsigned long timeCounter = 0; // where we're gonna store the amount of time to wait before buzzing | |
bool timeSet = false; //bool to determine whether time has been set or not | |
void setup(){ | |
Serial.begin(9600); | |
pinMode(buzzerPin, OUTPUT); // Set buzzerPin as an output | |
pinMode(buttonPin, INPUT); //Set buttonPin as input | |
} | |
void loop(){ | |
currentTime = millis(); | |
if(currentTime - buttonPressTime >= 100) { | |
buttonState = digitalRead(buttonPin); | |
buttonPressTime = currentTime; | |
} | |
if((buttonState == HIGH) && (buttonPressed == false)){ | |
timeCounter += 30000; //30 sec | |
buttonPressed = true; | |
offsetTime = millis(); | |
timeSet = true; | |
} else if (buttonState == LOW) { | |
buttonPressed = false; | |
} | |
Serial.println(timeCounter); | |
timeReset = (millis() - offsetTime); | |
if(timeSet){ | |
if(timeReset - previousTime >= timeCounter){ | |
previousTime = timeReset; | |
tone(buzzerPin, 1000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment