This shows you the differences between two versions of the page.
pm:prj2024:ddosaru:victor.udristioiu [2024/05/03 19:17] victor.udristioiu [Hardware Design] |
pm:prj2024:ddosaru:victor.udristioiu [2024/05/25 19:38] (current) victor.udristioiu [Descriere generală] |
||
---|---|---|---|
Line 3: | Line 3: | ||
<note tip> | <note tip> | ||
- | Prezentarea pe scurt a proiectului vostru: | + | Proiectul consta intr-o lampa inteligenta care reactioneaza la muzica, controlabila prin Bluetooth. Aceasta lampa este capabila sa interpreteze semnalele audio si sa sincronizeze efectele de lumina in timp real cu ritmul si intensitatea muzicii. Cu ajutorul unei aplicatii mobile, utilizatorii se pot conecta prin Bluetooth la lampa si sa controleze culorile, modelele si alte efecte luminoase, creand astfel o experienta vizuala unica si personalizata. |
- | * ce face | + | |
- | * care este scopul lui | + | |
- | * care a fost ideea de la care aţi pornit | + | |
- | * de ce credeţi că este util pentru alţii şi pentru voi | + | |
</note> | </note> | ||
===== Descriere generală ===== | ===== Descriere generală ===== | ||
<note tip> | <note tip> | ||
- | O schemă bloc cu toate modulele proiectului vostru, atât software cât şi hardware însoţită de o descriere a acestora precum şi a modului în care interacţionează. | + | Specificatii generale: |
+ | * Modulul Bluetooth ii va permite utilizatorului sa comande banda cu LEDuri prin intermediul uC-ului. | ||
+ | * Exista si un mod ambiental, ce va folosi datele primite de la senzorul de sunet pentru a schimba intensitatea si culorile in fuctie de ritmul si volumul muzicii. | ||
- | Exemplu de schemă bloc: http://www.robs-projects.com/mp3proj/newplayer.html | + | {{:pm:prj2024:ddosaru:schema_bloc_victor.png?200|}} |
</note> | </note> | ||
Line 21: | Line 19: | ||
<note tip> | <note tip> | ||
Componente: | Componente: | ||
- | * Arduino UNO | + | -Arduino UNO |
- | * Senzor Sunet 5V | + | -Senzor Sunet 5V |
- | -Modul Bluetooth HC-05 | + | -Modul Bluetooth HC-05 |
- | -Banda LED Adresabila WS2812 | + | -Banda LED Adresabila WS2812 |
- | -Breadboard | + | -Breadboard |
{{:pm:prj2024:ddosaru:schema_electrica.png?200|}} | {{:pm:prj2024:ddosaru:schema_electrica.png?200|}} | ||
</note> | </note> | ||
Line 33: | Line 31: | ||
<note tip> | <note tip> | ||
- | Descrierea codului aplicaţiei (firmware): | + | <code> |
- | * mediu de dezvoltare (if any) (e.g. AVR Studio, CodeVisionAVR) | + | #include "FastLED.h" |
- | * librării şi surse 3rd-party (e.g. Procyon AVRlib) | + | #include <SoftwareSerial.h> |
- | * algoritmi şi structuri pe care plănuiţi să le implementaţi | + | |
- | * (etapa 3) surse şi funcţii implementate | + | uint8_t r = 0; |
+ | uint8_t g = 0; | ||
+ | uint8_t b = 0; | ||
+ | uint8_t a = 0; | ||
+ | |||
+ | SoftwareSerial MyBlue(2, 3); // RX | TX | ||
+ | |||
+ | #define NUM_LEDS 60 | ||
+ | #define PIN 6 | ||
+ | #define INPUT_SIZE 32 | ||
+ | #define ANALOG_READ A0 | ||
+ | const byte MAX_STRING_LEN = 32; | ||
+ | char incoming_value = 0; | ||
+ | |||
+ | int state = 0; | ||
+ | int prev_state = 0; | ||
+ | |||
+ | CRGB leds[NUM_LEDS]; | ||
+ | |||
+ | char inputString[MAX_STRING_LEN]; | ||
+ | byte strLen = 0; | ||
+ | |||
+ | void setup() { | ||
+ | state = 0; | ||
+ | Serial.begin(9600); | ||
+ | MyBlue.begin(9600); | ||
+ | FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); | ||
+ | FastLED.setBrightness(100); | ||
+ | randomSeed(analogRead(0)); | ||
+ | } | ||
+ | |||
+ | boolean processSerial() { | ||
+ | while (MyBlue.available()) { | ||
+ | char inChar = (char)MyBlue.read(); | ||
+ | |||
+ | if ((inChar == '\n') || (inChar == '\r')) | ||
+ | return true; | ||
+ | |||
+ | if (strLen < (MAX_STRING_LEN - 1)) { | ||
+ | inputString[strLen++] = inChar; | ||
+ | inputString[strLen] = '\0'; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | return false; | ||
+ | } | ||
+ | |||
+ | void compute_next_state() | ||
+ | { | ||
+ | if (processSerial()) { | ||
+ | if(strstr(inputString, "on")) | ||
+ | { | ||
+ | state = 1; | ||
+ | } | ||
+ | else if (strstr(inputString, "off")) | ||
+ | { | ||
+ | state = 2; | ||
+ | } | ||
+ | else if (strstr(inputString, "music")) | ||
+ | { | ||
+ | state = 4; | ||
+ | } | ||
+ | else if (strstr(inputString, "&")) | ||
+ | { | ||
+ | char* token = strtok(inputString, "&"); | ||
+ | int count = 0; | ||
+ | while(token) | ||
+ | { | ||
+ | if (count == 0) | ||
+ | r = (uint8_t)atoi(token); | ||
+ | |||
+ | if (count == 1) | ||
+ | g = (uint8_t)atoi(token); | ||
+ | |||
+ | if (count == 2) | ||
+ | b = (uint8_t)atoi(token); | ||
+ | count++; | ||
+ | token = strtok(NULL, "&"); | ||
+ | } | ||
+ | state = 3; | ||
+ | } | ||
+ | |||
+ | inputString[0] = '\0'; | ||
+ | strLen = 0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | if (state == 0) | ||
+ | { | ||
+ | compute_next_state(); | ||
+ | } | ||
+ | if (state == 1) | ||
+ | { | ||
+ | FastLED.setBrightness(100); | ||
+ | for(int i = 0; i < NUM_LEDS; i++) { | ||
+ | leds[i].setRGB(255, 255, 255); | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | state = 0; | ||
+ | } | ||
+ | if (state == 2) | ||
+ | { | ||
+ | FastLED.setBrightness(100); | ||
+ | for(int i = 0; i < NUM_LEDS; i++) { | ||
+ | leds[i].setRGB(0, 0, 0); | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | state = 0; | ||
+ | } | ||
+ | if (state == 3) | ||
+ | { | ||
+ | FastLED.setBrightness(100); | ||
+ | for(int i = 0; i < NUM_LEDS; i++) { | ||
+ | leds[i].setRGB(r, g, b); | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | state = 0; | ||
+ | } | ||
+ | if (state == 4) | ||
+ | { | ||
+ | for(int i = 0; i < NUM_LEDS; i++) { | ||
+ | leds[i].setRGB(0, 0, 0); | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | |||
+ | long sum = 0; | ||
+ | for(int i=0; i<300; i++) | ||
+ | { | ||
+ | sum += analogRead(ANALOG_READ); | ||
+ | } | ||
+ | |||
+ | sum = sum/300; | ||
+ | FastLED.setBrightness(random(100)); | ||
+ | |||
+ | int no_leds = map(sum, 40, 900, 0, 59); | ||
+ | |||
+ | if(no_leds < NUM_LEDS) | ||
+ | { | ||
+ | for(int i = 0; i < no_leds; i++) { | ||
+ | leds[i].setRGB(random(255), random(255), random(255)); | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | } | ||
+ | delay(10); | ||
+ | if (!MyBlue.available()) | ||
+ | state = 4; | ||
+ | else | ||
+ | state = 0; | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
</note> | </note> | ||
Line 69: | Line 218: | ||
<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> | ||
- | |||