mc_workshop

WU meter 1.0 2 channel

Feb 4th, 2019
92
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Wu Meter
  2. //This example code is in the public domain.
  3. // by Marco C.
  4. const int nleds = 4; //mettere il numero di led corrispondenti a quanti ne montate
  5. const int nleds2 = 4;
  6. const int ledPins [] = {4, 5, 6, 7}; //dichiarate su quali pin sono collegati i led
  7. const int ledPins2 [] = {12, 11, 10, 9};
  8. const int analogInPin = A0; //l'ingresso del segnale proveniente dalle cuffie è su A0
  9. const int analogInPin2 = A1;
  10. const boolean LED_ON = HIGH;
  11. const boolean LED_OFF = LOW;
  12. int sensorValue = A0;
  13. int sensorValue2 = A1;
  14. int ledLevel = A0;
  15. int ledLevel2 = A1;
  16. void setup() {
  17.   for (int led = 0; led < nleds; led++)
  18.     for (int led = 0; led < nleds2; led++)
  19.     {
  20.       pinMode (ledPins[led], OUTPUT);
  21.       pinMode (ledPins2[led], OUTPUT);
  22.     }
  23. }
  24. void loop() {
  25.   sensorValue = analogRead (analogInPin);
  26.   sensorValue2 = analogRead (analogInPin2);
  27.   ledLevel = map(sensorValue, 0, 10, 0 , nleds);
  28.   ledLevel2 = map(sensorValue2, 0, 10, 0 , nleds); // la mappatura va cambiata in base al segnale delle cuffie 0, 10, 0 , NbrLEDs
  29.   for (int led = 0; led < nleds; led++)
  30.     for (int led = 0; led < nleds2; led++)
  31.     {
  32.       if (led < ledLevel) {
  33.         digitalWrite(ledPins[led], LED_ON);
  34.       }
  35.       else {
  36.         digitalWrite(ledPins[led], LED_OFF);
  37.       }
  38.       if (led < ledLevel2) {
  39.         digitalWrite(ledPins2[led], LED_ON);
  40.       }
  41.       else {
  42.         digitalWrite(ledPins2[led], LED_OFF);
  43.       }
  44.     }
  45. }
RAW Paste Data