-
Notifications
You must be signed in to change notification settings - Fork 0
/
neopot.ino
43 lines (35 loc) · 1.11 KB
/
neopot.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <Adafruit_NeoPixel.h>
#define PIN 6
int stripLen = 16;
int sensorPin = A0;
int sensorVal;
int pixelPos;
int pixelOn;
int pixelOff;
int pixelMap;
int brightnessMap;
void setup() {
Serial.begin(9600);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
sensorVal = analogRead(sensorPin); // incoming values are 10-bit: 0 - 1023
pixelPos = sensorVal/64; // downsample to 4-bit values: 0 - 15 (number of pixels)
pixelMap = pixelPos*64; // reverse upsample 4-bit values to 8-bit block-resolution
brightnessMap = sensorVal - pixelMap; //map((sensorVal - pixelMap), 0, 63, 0, 255); // remap 0 - 63 to 0 - 255 (more precise than * 4)
//Serial.println(brightnessMap);
refresh(pixelPos, brightnessMap);
//delay (10);
}
void refresh(int currentPos, int brightness){
for (int j = 0; j < currentPos+1; j++){
int greenMap = map(brightness, 0, 255, 0, 155);
strip.setPixelColor(pixelPos, 0, brightness, brightness);
strip.show();
}
for (int i = stripLen; i > currentPos; i--){
strip.setPixelColor(i, 0, 0, 0);
strip.show();
}
}