Skip to content

Instantly share code, notes, and snippets.

@todocono
Last active March 5, 2024 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todocono/8b77a741e0580987901b1d8c2dcdf9b6 to your computer and use it in GitHub Desktop.
Save todocono/8b77a741e0580987901b1d8c2dcdf9b6 to your computer and use it in GitHub Desktop.
//Millis example
//Coded during class - Interaction Lab
//NYUSH IMA
//Mar 5 2024
int val;
int prevVal;
long startTime;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(8, OUTPUT);
}
void loop() {
// if (millis() < 1000) {
// tone(8, 262);
// }
// if (millis() > 1000 && millis() < 2000) {
// tone(8, 330);
// }
// if (millis() > 2000 && millis() < 3000) {
// tone(8, 392);
// }
// if (millis() > 3000) {
// noTone(8);
// }
if (millis() % 1000 < 10) {
//Serial.println("one second passed");
tone(8, 392,100);
}
if ((millis() % 1000 < 110) && (millis() % 1000 > 100)) {
noTone(8);
}
val = digitalRead(2);
if (prevVal == LOW && val == HIGH) {
Serial.println("Pressed");
startTime = millis();
}
if (prevVal == HIGH && val == LOW) {
Serial.print("Released after ");
Serial.println(millis() - startTime);
}
prevVal = val;
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment