This shows you the differences between two versions of the page.
|
pm:prj2024:ddosaru:victor.udristioiu [2024/05/25 19:33] victor.udristioiu [Software Design] |
pm:prj2024:ddosaru:victor.udristioiu [2024/05/25 19:38] (current) victor.udristioiu [Descriere generală] |
||
|---|---|---|---|
| Line 9: | Line 9: | ||
| <note tip> | <note tip> | ||
| Specificatii generale: | Specificatii generale: | ||
| - | Modulul Bluetooth ii va permite utilizatorului sa comande banda cu LEDuri prin intermediul uC-ului. | + | * 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. | + | * 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. |
| {{:pm:prj2024:ddosaru:schema_bloc_victor.png?200|}} | {{:pm:prj2024:ddosaru:schema_bloc_victor.png?200|}} | ||
| Line 19: | 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 31: | 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> | ||