-
Notifications
You must be signed in to change notification settings - Fork 0
/
val01.ino
82 lines (65 loc) · 1.88 KB
/
val01.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <Adafruit_NeoPixel.h>
#define NeoPixelOutPin 17
#define NeoPixelInPin 16
#define NumPixels 8
#define AnalogInPin 26
#define AnalogOutPin 15
#define LogInPin1 0
#define LogInPin2 1
#define LogOutPin 2
int setColor[5][3] = {{255, 255, 255}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {0, 0, 0} };
Adafruit_NeoPixel pixels(NumPixels, NeoPixelOutPin, NEO_GRB + NEO_KHZ800);
int LogMode = random(1, 4);
void setup() {
pixels.begin();
pixels.setBrightness(20);
pinMode(NeoPixelInPin, INPUT);
pinMode(AnalogOutPin, OUTPUT);
pinMode(LogInPin1, INPUT);
pinMode(LogInPin2, INPUT);
pinMode(LogOutPin, OUTPUT);
}
int j = -1;
void loop() {
/***** ENGINE ******/
int adcVal = analogRead(AnalogInPin)+200; //read adc
double voltage = adcVal / 1023.0 * 3.3;
if(voltage < 1){
digitalWrite(AnalogOutPin, LOW);
}else{
analogWrite(AnalogOutPin, map(adcVal, 0, 1023, 0, 255));
}
/***** ENGINE ******/
/***** LOGIC ******/
if(LogMode == 1) {
if(digitalRead(LogInPin1) && digitalRead(LogInPin2)){
digitalWrite(LogOutPin, HIGH);
}else{
digitalWrite(LogOutPin, LOW);
}
} else if (LogMode == 2) {
if(digitalRead(LogInPin1) || digitalRead(LogInPin2)){
digitalWrite(LogOutPin, HIGH);
}else{
digitalWrite(LogOutPin, LOW);
}
} else if (LogMode == 3) {
if(digitalRead(LogInPin1) && !digitalRead(LogInPin2) || !digitalRead(LogInPin1) && digitalRead(LogInPin2)){
digitalWrite(LogOutPin, HIGH);
}else{
digitalWrite(LogOutPin, LOW);
}
}
/***** LOGIC ******/
/***** NEO PIXEL ******/
if(digitalRead(NeoPixelInPin) == LOW) {
j = j+1;
LogMode = random(1, 4);
for (int i = 0; i < NumPixels; i++) {
pixels.setPixelColor(i, setColor[j][0], setColor[j][1], setColor[j][2]); pixels.show();
delay(100);
}
if(j==4) j=-1;
}
/***** NEO PIXEL ******/
}