Kobayashi
Ahn'Qiraj Raider
- 1,023
- 2,899
I can't play around with the emulator at the moment, but I think your code is just addressing the one LED and then clearing things out with every loop.Looking for some feedback with my Pi/Arduino code since I'm now stuck and can't figure out why it's not doing what I want it to do.
I'm creating a HiFi Pi/Arduino musicbox. I will be using a potentiometer to control the volume and the value of the potentiometer will also illuminate a NEOPIXEL ring as teh volume changes.
I have got the potentiometer working, I can even get the LED light to illuminate but only one LED at a time. This may work but I'm thinking it'll be too hard to see and I'll need the full LED ring to light up as the volume goes up, and goes away as volume is decreased. When I try this in the code the lights never "turn off" when volume is increased.
If someone could give me some direction I'd appreciate it.
The code below works correctly with the single LED moving the full range, this mainly works because of the "strip.clear();" line of code near the bottom. If this line of code is removed, the ring will light up as volume increases but will not go away when volume is lowered.
Feel free to test this here with the emulator, the code is already in place and ready to go.
C++://Notes// //Pot Min 0 Pot Max 1023 // Expected range for raspi 0 to 255 //Libraries #include <Adafruit_NeoPixel.h> #define PIN 9 #define NUM_LIGHTS 24 Adafruit_NeoPixel strip(24, 9, NEO_GRB + NEO_KHZ800); //Variables int analogInput = A0; //Input for reading Potentiometer value int potValue = 0; int LEDColor = 0; //Value read from Potentiometer void setup() { Serial.begin(9600); //Setup USB Serial output strip.begin(); //Enable LED ring strip.show(); //Turns all LEDS off on LED ring } void loop() { potValue = analogRead(analogInput); potValue = map(potValue, 0, 1023, 0, 255); // Change the range of the pot value to match the digital signal required by the RasPi Serial.println(potValue); //Display value of Potentiometer delay(15); //Time delay for Potentiometer reading stability LEDColor = (potValue); //Convert Potentiometer value for LED control puproses LEDColor = map(LEDColor, 1, 255, 0, 24); //Map the Potentiometer value to a range that matches the number of pins on the LED Ring strip.setPixelColor(LEDColor, 255); //Set the pixel color and change the LEDs illuminated as the volume is increased strip.show(); strip.clear(); } void println(int potValue){ Serial.print(potValue); }
I'm thinking what you want to do is add a for loop to address each LED up to that value.
- 1