This shows you the differences between two versions of the page.
|
pm:prj2025:mdinica:alin_ioan.alexandru [2025/05/28 00:12] alin_ioan.alexandru [Rezultate Obţinute] |
pm:prj2025:mdinica:alin_ioan.alexandru [2025/05/28 13:27] (current) alin_ioan.alexandru [Software Design] |
||
|---|---|---|---|
| Line 161: | Line 161: | ||
| return digitalRead(sigPin); | return digitalRead(sigPin); | ||
| } | } | ||
| + | |||
| + | </code> | ||
| + | |||
| + | Timer: | ||
| + | |||
| + | <code cpp> | ||
| + | |||
| + | volatile int timeRemaining = 0; // Init when game starts | ||
| + | volatile bool updateLCD = false; | ||
| + | |||
| + | void tick() { | ||
| + | if (timeRemaining > 0) { | ||
| + | timeRemaining--; | ||
| + | updateLCD = true; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void startTimer(int secunde) { | ||
| + | timeRemaining = secunde; | ||
| + | timerTicker.attach(1.0, tick); | ||
| + | } | ||
| + | |||
| + | void stopTimer() { | ||
| + | timerTicker.detach(); | ||
| + | timeRemaining = 0; | ||
| + | updateLCD = true; | ||
| + | } | ||
| + | |||
| + | </code> | ||
| + | |||
| + | Comunicare prin bluetooth: | ||
| + | |||
| + | <code cpp> | ||
| + | |||
| + | if (SerialBT.available()) { | ||
| + | String mesaj = SerialBT.readStringUntil('\n'); | ||
| + | mesaj.trim(); | ||
| + | mesaj.toLowerCase(); | ||
| + | |||
| + | if (mesaj == "start") { | ||
| + | startTimer(5 * 60); // 5 minute | ||
| + | SerialBT.println("Timer pornit"); | ||
| + | } else if (mesaj == "reset") { | ||
| + | stopTimer(); | ||
| + | SerialBT.println("Timer oprit/resetat"); | ||
| + | } else { | ||
| + | SerialBT.println("Comanda necunoscuta"); | ||
| + | } | ||
| + | } | ||
| </code> | </code> | ||