//Code to control the LED bar graphs to show how many supplies are in the containers based on weight
const int activeLeds = 10;
int activeLedPins[] = {A0, A2, D0, D1, D2, D3, D4, D5, D6, D7}; // an array of pin numbers to which LEDs are attached
int inactiveLedPin1 = A3;
int inactiveLedPin2 = A4;
int numLeds = 0;
void setup() {
// loop over the pin array and set them all to output:
for (int i = 0; i < activeLeds; i++) {
pinMode(activeLedPins[i], OUTPUT);
digitalWrite(activeLedPins[i], LOW);
}
pinMode(inactiveLedPin1, OUTPUT);
pinMode(inactiveLedPin2, OUTPUT);
digitalWrite(inactiveLedPin1, HIGH);
digitalWrite(inactiveLedPin2, HIGH);
Spark.subscribe("JJIoTFinal15capacity", adjustDisplay);
}
void loop() {
delay(1000);
}
void adjustDisplay(const char *event, const char *data) {
if (*data == 'H') {
numLeds = 10;
}
else if (*data == 'M') {
numLeds = 5;
}
else if (*data == 'L') {
numLeds = 1;
}
else {
numLeds = 0;
}
for (int i = 0; i < activeLeds; i++) {
digitalWrite(activeLedPins[i], LOW);
}
for (int i = 0; i < numLeds; i++) {
digitalWrite(activeLedPins[i], HIGH);
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .