Last active
March 5, 2024 07:56
-
-
Save todocono/8b77a741e0580987901b1d8c2dcdf9b6 to your computer and use it in GitHub Desktop.
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
//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