Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pm:prj2024:ddosaru:victor.udristioiu [2024/05/03 23:21]
victor.udristioiu [Descriere generală]
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 StudioCodeVisionAVR+#include "​FastLED.h"​ 
-  ​* librării şsurse 3rd-party ​(e.g. Procyon AVRlib+#include <​SoftwareSerial.h>​ 
-  ​* algoritmi şstructuri pe care plănuiţsă le implementaţ+ 
-  ​* ​(etapa 3surse ş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,​ "&"​)) 
 +      { 
 +        chartoken = strtok(inputString,​ "&"​);​ 
 +        int count = 0; 
 +        while(token) 
 +        { 
 +          ​if (count == 0) 
 +            r = (uint8_t)atoi(token);​ 
 + 
 +          if (count == 1) 
 +            ​= (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,​ 255255)
 +    } 
 +    FastLED.show();​ 
 +    state = 0; 
 +  ​
 +  if (state == 2) 
 +  { 
 +    FastLED.setBrightness(100);​ 
 +    for(int ​= 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 ​= 0; < 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 67: 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>​
- 
  
pm/prj2024/ddosaru/victor.udristioiu.1714767718.txt.gz · Last modified: 2024/05/03 23:21 by victor.udristioiu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0