-
Notifications
You must be signed in to change notification settings - Fork 0
/
MindMakersTasteBud.ino
112 lines (100 loc) · 3.75 KB
/
MindMakersTasteBud.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//Hello Mind Makers, to add your own comments and notes start a line with "//"
// The #include means that your arduino will use the prebuilt NeoPixel Library. This library contains lots of prewritten commands that make controlling your neopixel easy! Google or search on Adafruit.com the Neopixel library for help and ideas
#include <Adafruit_NeoPixel.h>
//This is the pin your Arduino will use to communicate with the NeoPixels.
#define PIN 6
//these commands define where your switches are plugged into the arudino, tells your arduino the number of switches you have, and sets their initial value to 0.
int swLocs[] = {7, 8, 9};
int swVals[] = {0, 0, 0};
int numSw = 3;
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(36, PIN, NEO_GRB + NEO_KHZ800);
// void setup() is a section of code where commands and variables can be initialized. For example in this code we use the NeoPixel library function "strip.begin()" to start communicating with the LED rings
void setup()
{
Serial.begin(9600);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
for (int i = 0; i < numSw; i++)
{
pinMode(swLocs[i], INPUT);
}
}
// void loop() is what your arduino will running over and over once it gets through the initialization and void setup()
// in this loop we have a condition where we call a function called "anyTrue" that checks to see if any of the tactile switches are pressed, and if so which one
// if the switches are pressed, our main loop continues into a "while" loop that changes the behavior of the LED rings
// To play on your own and add functionality, it is possible to change how the "anyTrue function works and what data it sends to the main loop, it is possible to change the behavior of the tastebud when switches are pressed
// and its possible to add your own ideas and behaviors!
void loop()
{
int pressed = anyTrue();
while (pressed > 0)
{
if (pressed == 1) {
// if button one is pressed
if (swVals[0] == 1) {
for (int i = 0; i < 36; i++)
{
strip.setPixelColor(i, 250, 0, 170); // pink
strip.show();
}
// if button two is pressed
} else if (swVals[1] == 1) {
for (int i = 0; i < 36; i++)
{
strip.setPixelColor(i, 32, 178, 170); // light green
strip.show();
}
// if button three is pressed
} else if (swVals[2] == 1) {
for (int i = 0; i < 36; i++)
{
strip.setPixelColor(i, 255, 233, 0); // yellow
strip.show();
}
}
} else if (pressed == 2) {
for (int i = 0; i < 36; i++)
{
strip.setPixelColor(i, 255, 0, 0);
strip.show();
}
} else if (pressed == 3) {
for (int i = 0; i < 36; i++)
{
strip.setPixelColor(i, random(0, 255), random(0, 255), random(0, 255)); // picks a random RGB value
strip.show();
}
delay(500); // wait 500 milliseconds
}
pressed = anyTrue();
}
for (int m = 0; m < 36; m++)
{
strip.setPixelColor(m, 80, 0, 110);
strip.show();
}
}
//Here is the function "anyTrue"
int anyTrue() {
int count = 0;
for (int k = 0; k < numSw; k++)
{
swVals[k] = digitalRead(swLocs[k]);
}
for (int i = 0; i < numSw; i++)
{
if (swVals[i] != 0)
{
count += 1;
}
}
Serial.println(count);
return count;
}