Hi!
I'm working on my first project with the Digispark. The project includes four 48" dowels inset with an RGB LED, proximity sensor, and Digispark. I am programming the RGB LED strip and will leave the Digisparks in the dowels permanently.
First, I was wondering if I could get some help with the code. The effect I am trying to create is as follows: RGB LED strip "breathing" in a blue monochrome. When person enters range of proximity sensor, the LED strip breathes at the same rate, but brightens increasingly as proximity increases.
Here is what I've been working with:
[/quote]#include <SPI.h>
int sensorPin = A3; // the pin that the sensor is attached to
int LEDpin = 9; // the pin that the LED is attached to
int proximity;
int pwmActual[] = {
0, 1, 2, 3, 4, 5, 7, 9,
12, 15, 18, 22, 27, 32, 37, 44,
50, 58, 66, 75, 85, 96, 107, 120,
133, 147, 163, 179, 196, 215, 234, 255
};
float counter;
float val;
int minMap, maxMap;
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(LEDpin, OUTPUT);
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
proximity = analogRead(sensorPin); // returns 0 to 1023 in theory (0-5V), but TEST SENSOR
// Serial.println(proximity);
minMap = map(proximity, 0,1023, 0,45);
maxMap = minMap + 128;
counter += .1;
val = sin(counter) * 1000;
val = map(val, -1025,1025, minMap, maxMap);
analogWrite(LEDpin, val);
//Serial.println(sin(counter));
Serial.println(maxMap);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
[quote]Right now, I'm very close, but it needs to be tweaked. I'd like for the peak brightness to be much lower when the viewer is out of range of the sensor. I'm okay with the rest of it. Can anyone help?
I haven't used the Digispark at all yet, and I'm also still pretty new to Arduino in general, so no advice is too basic. I plan on searching the website now for any libraries, etc., that will be necessary for the software to play nicely with Digispark, but feel free to suggest anything that third-party users have created that I might not be aware would help.
As far as physical construction, the LED strip requires 12v. I'll be powering with 8 AAs in series, and using a 5v voltage regulator from power to the Digispark. Then, from Digispark to LED strip, I'll be following the Adafruit tutorial here:
http://learn.adafruit.com/rgb-led-strips/usageDoes anyone foresee any issues with this, or does it look pretty good?
I should note, in case it's not clear from the code, that up until now, I have been testing the code with a single LED . . . not with the strip.
Thanks!