This shows you the differences between two versions of the page.
pm:prj2023:avaduva:basketball_score_counter [2023/05/30 03:13] vlad.paraschiv1511 [Software Design] |
pm:prj2023:avaduva:basketball_score_counter [2023/05/30 04:00] (current) vlad.paraschiv1511 [Download] |
||
---|---|---|---|
Line 17: | Line 17: | ||
==Schema:== | ==Schema:== | ||
- | {{ :pm:prj2023:avaduva:pvschema.png}} | + | {{ :pm:prj2023:avaduva:pvschema2.png}} |
===== Hardware Design ===== | ===== Hardware Design ===== | ||
Line 30: | Line 30: | ||
*LCD display | *LCD display | ||
- | ===== Hardware Scheme ===== | + | 1. Hardware Scheme |
+ | |||
+ | {{ :pm:prj2023:avaduva:schemapv2.png?700}} | ||
+ | |||
+ | 2. Hardware | ||
+ | |||
+ | {{ :pm:prj2023:avaduva:fire.jpeg?700}} | ||
+ | |||
+ | |||
- | {{ :pm:prj2023:avaduva:schemapv2.png}} | ||
===== Software Design ===== | ===== Software Design ===== | ||
Line 51: | Line 59: | ||
. | . | ||
. | . | ||
+ | void loop() { | ||
long countdowntime_seconds = countdown_time - (millis() / 1000); | long countdowntime_seconds = countdown_time - (millis() / 1000); | ||
if (countdowntime_seconds >= 0) { | if (countdowntime_seconds >= 0) { | ||
Line 68: | Line 77: | ||
. | . | ||
. | . | ||
+ | . | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | 2.Control LED + LCD | ||
+ | <code> | ||
+ | #define LED_PIN 2 | ||
+ | #define LED_COUNT 6 | ||
+ | LiquidCrystal_I2C lcd(0x27, 16, 2); | ||
+ | Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); | ||
+ | |||
+ | void setup() { | ||
+ | lcd.init(); | ||
+ | lcd.backlight(); | ||
+ | lcd.setCursor(4, 0); | ||
+ | lcd.print("score:"); | ||
+ | lcd.setCursor(11, 0); | ||
+ | lcd.print(score); | ||
+ | |||
+ | strip.begin(); | ||
+ | strip.show(); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | . | ||
+ | . | ||
+ | . | ||
+ | if (countdowntime_seconds <= 60 && countdowntime_seconds > 40) { | ||
+ | setColor(strip.Color(0, 255, 0)); // Green | ||
+ | } else if (countdowntime_seconds <= 40 && countdowntime_seconds > 20) { | ||
+ | setColor(strip.Color(255, 255, 0)); // Yellow | ||
+ | } else if (countdowntime_seconds <= 20 && countdowntime_seconds > 0) { | ||
+ | setColor(strip.Color(255, 0, 0)); // Red | ||
+ | } else { | ||
+ | strip.clear(); // Turn off LED strip | ||
+ | strip.show(); | ||
+ | } | ||
+ | |||
+ | if (countdowntime_seconds == 0) { | ||
+ | lcd.setCursor(4, 1); | ||
+ | lcd.print("Time's up"); | ||
+ | strip.clear(); // Turn off LED strip | ||
+ | strip.show(); | ||
+ | } | ||
+ | } | ||
+ | delay(500); | ||
+ | } | ||
+ | |||
+ | void setColor(uint32_t color) { | ||
+ | for (int i = 0; i < LED_COUNT; i++) { | ||
+ | strip.setPixelColor(i, color); | ||
+ | } | ||
+ | strip.show(); | ||
+ | } | ||
+ | </code> | ||
+ | 3. Setup Senzor Ultrasonic | ||
+ | |||
+ | <code> | ||
+ | const int triggerPin = 7; | ||
+ | const int echoPin = 6; | ||
+ | int score = 0; | ||
+ | . | ||
+ | . | ||
+ | . | ||
+ | void setup() { | ||
+ | pinMode(triggerPin, OUTPUT); | ||
+ | pinMode(echoPin, INPUT); | ||
+ | . | ||
+ | . | ||
+ | . | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | long duration; | ||
+ | int distance; | ||
+ | |||
+ | digitalWrite(triggerPin, LOW); | ||
+ | delayMicroseconds(2); | ||
+ | |||
+ | digitalWrite(triggerPin, HIGH); | ||
+ | delayMicroseconds(10); | ||
+ | |||
+ | digitalWrite(triggerPin, LOW); | ||
+ | duration = pulseIn(echoPin, HIGH); | ||
+ | distance = duration * 0.032 / 2; | ||
+ | |||
+ | if (distance < 10) { | ||
+ | score++; | ||
+ | lcd.setCursor(11,0); | ||
+ | lcd.print(score); | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | 4.Setup Buzzer | ||
+ | |||
+ | <code> | ||
+ | const int buzzerPin = 9; | ||
+ | . | ||
+ | . | ||
+ | . | ||
+ | void setup() { | ||
+ | pinMode(buzzerPin, OUTPUT); | ||
+ | } | ||
+ | . | ||
+ | . | ||
+ | . | ||
+ | void loop { | ||
+ | if (distance < 10) { | ||
+ | score++; | ||
+ | lcd.setCursor(11,0); | ||
+ | lcd.print(score); | ||
+ | playSound(); | ||
+ | } | ||
+ | . | ||
+ | . | ||
+ | . | ||
+ | } | ||
+ | void playSound() { | ||
+ | tone(buzzerPin, 1000, 100); | ||
+ | delay(100); | ||
+ | noTone(buzzerPin); | ||
+ | } | ||
</code> | </code> | ||
===== Rezultate Obţinute ===== | ===== Rezultate Obţinute ===== | ||
Line 103: | Line 236: | ||
===== Concluzii ===== | ===== Concluzii ===== | ||
- | ===== Download ===== | + | Tot procesul de facere a proiectului a fost o experiență interesantă și oarecum distractivă, dar care nu a fost întocmai ușoară. |
- | <note warning> | + | Construirea proiectului a fost cu siguranță o activitate plăcută, deși pe parcurs am întâmpinat mai multe probleme cu hardware-ul folosit. |
- | O arhivă (sau mai multe dacă este cazul) cu fişierele obţinute în urma realizării proiectului: surse, scheme, etc. Un fişier README, un ChangeLog, un script de compilare şi copiere automată pe uC crează întotdeauna o impresie bună ;-). | + | |
- | Fişierele se încarcă pe wiki folosind facilitatea **Add Images or other files**. Namespace-ul în care se încarcă fişierele este de tipul **:pm:prj20??:c?** sau **:pm:prj20??:c?:nume_student** (dacă este cazul). **Exemplu:** Dumitru Alin, 331CC -> **:pm:prj2009:cc:dumitru_alin**. | + | Dezvoltarea codului a fost puțin mai provocatoare decât m-aș fi așteptat, din cauza problemelor pe care le-am avut cu senzorul ultrasonic.(probleme care au o șansă să mai apară din când în când) |
- | </note> | + | |
+ | Una peste alta, acest proiect m-a ajutat sa învăț destul de multe și a fost probabil partea mea preferată a acestui semestru. | ||
+ | ===== Download ===== | ||
+ | |||
+ | {{:pm:prj2023:avaduva:ma.rar|}}\\ | ||
===== Jurnal ===== | ===== Jurnal ===== | ||
Line 119: | Line 255: | ||
===== Bibliografie/Resurse ===== | ===== Bibliografie/Resurse ===== | ||
- | <note> | + | [[https://lastminuteengineers.com/i2c-lcd-arduino-tutorial/ | Utilizare LCD]]\\ |
- | Listă cu documente, datasheet-uri, resurse Internet folosite, eventual grupate pe **Resurse Software** şi **Resurse Hardware**. | + | [[https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/ | Utilizare HC-SR04]]\\ |
- | </note> | + | Laboratorul 6 |
<html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | ||