Differences

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

Link to this comparison view

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 30: Line 30:
  
  
 +<note tip>
 +<​code>​
 #include "​FastLED.h"​ #include "​FastLED.h"​
 #include <​SoftwareSerial.h>​ #include <​SoftwareSerial.h>​
Line 55: Line 57:
 byte strLen ​  = 0;  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>​
  
 ===== Rezultate Obţinute ===== ===== Rezultate Obţinute =====
pm/prj2024/ddosaru/victor.udristioiu.1716654818.txt.gz · Last modified: 2024/05/25 19:33 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