Lights Outs
Made by atesfaye, Richard Dong and Harshine Varuna Visvanathan · UNLISTED (SHOWN IN POOLS)
Made by atesfaye, Richard Dong and Harshine Varuna Visvanathan · UNLISTED (SHOWN IN POOLS)
Created: October 11th, 2019
int redLedPin = D0;
int greenLedPin = D1;
int blueLedPin = D2;
int redButtonPin = D3;
int greenButtonPin = D4;
int blueButtonPin = D5;
int switchPowerPin = D7;
int switchPin = D8;
char *send_arr;
char *receive_arr;
int send_arr_count;
#define ARR_LENGTH 9
void setup() {
pinMode(redLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(blueLedPin, OUTPUT);
pinMode(switchPowerPin, OUTPUT);
digitalWrite(switchPowerPin, HIGH);
pinMode(redButtonPin, INPUT_PULLUP);
pinMode(greenButtonPin, INPUT_PULLUP);
pinMode(blueButtonPin, INPUT_PULLUP);
pinMode(switchPin, INPUT_PULLDOWN);
Time.zone(-4);//set to est
send_arr = (char*) calloc(ARR_LENGTH+1, sizeof(char));
receive_arr = (char*) calloc(ARR_LENGTH+1, sizeof(char));
send_arr_count = 0;
setupReceiver();
Serial.begin(9600);
}
void setupReceiver() {
Particle.subscribe("button-presses", buttonPresses, MY_DEVICES);
}
void loop() {
if (isButtonPressed(switchPin)) {
loopReceiver();
} else {
loopSender();
}
}
void loopReceiver() {
send_arr_count = 0;
char but = 0;
int on_time = 200;
int off_time = 100;
delay(1000);
for(int i = 0; i < ARR_LENGTH; i++) {
if (receive_arr[i] == '0') {
digitalWrite(redLedPin, HIGH);
delay(on_time);
digitalWrite(redLedPin, LOW);
delay(off_time);
} else if (receive_arr[i] == '1') {
digitalWrite(greenLedPin, HIGH);
delay(on_time);
digitalWrite(greenLedPin, LOW);
delay(off_time);
} if (receive_arr[i] == '2') {
digitalWrite(blueLedPin, HIGH);
delay(on_time);
digitalWrite(blueLedPin, LOW);
delay(off_time);
}
}
}
void buttonPresses(const char *event, const char *data) {
for(int i =0; i < ARR_LENGTH; i++) {
receive_arr[i] = data[i];//copy into our array
}
}
bool isButtonPressed(int pin) {
int digitalValue = digitalRead(pin);
//Serial.printf("Pin %d has value %d\n", pin, digitalValue);
return digitalValue == LOW;
}
void loopSender() {
if(isButtonPressed(redButtonPin)) {
digitalWriteFast(redLedPin, HIGH);
if (send_arr_count == 0 || send_arr[send_arr_count-1] != '0') {
send_arr[send_arr_count++] = '0';
}
//digitalWrite(greenLedPin, LOW);
//digitalWrite(blueLedPin, LOW);
} else if(isButtonPressed(greenButtonPin)) {
//digitalWrite(redLedPin, LOW);
if (send_arr_count == 0 || send_arr[send_arr_count-1] != '1') {
send_arr[send_arr_count++] = '1';
}
digitalWriteFast(greenLedPin, HIGH);
//digitalWrite(blueLedPin, LOW);
} else if(isButtonPressed(blueButtonPin)) {
//digitalWrite(redLedPin, LOW);
if (send_arr_count == 0 || send_arr[send_arr_count-1] != '2') {
send_arr[send_arr_count++] = '2';
}
//digitalWrite(greenLedPin, LOW);
digitalWriteFast(blueLedPin, HIGH);
} else {
digitalWriteFast(redLedPin, LOW);
digitalWriteFast(greenLedPin, LOW);
digitalWriteFast(blueLedPin, LOW);
}
if(send_arr_count == ARR_LENGTH) {
send_arr[ARR_LENGTH] = '\0';
Particle.publish("button-presses", send_arr, PRIVATE);
send_arr_count = 0;
}
}
Click to Expand
Conceptual Design
A scenario for this product is that a travelling business women might want to interact with her kid from far away. With this device, she can send button presses that the child would see and associate with her presence. The kid could also send button presses by flipping the switch to send mode.
Parts
Two Particle Argon
8 leds
6 buttons
2 switches
20 wires
Process
We initially spent most of our time figuring out how to get button presses to light up an LED and read that the button is pressed in the code. We had to experiment with different wiring solutions since we first had the button complete the circuit with the wire. We changed this to have the particle supply the led with power, and we also had to use pull down functionality to light up the led.
After this, we began to work on the networking components. We chose to use a string as our data format. After 9 button presses, the sender device will send the string over the network to the other device. Each character of the string encodes a button press. When the other device receives this string, it will iterate through the characters and light up the appropriate light.
We finally implemented the switch functionality, so that we could switch the devices on the fly from sender to receiver and vice versa.
This project is only listed in this pool. Be considerate and think twice before sharing.
Thermostats, locks, power sockets, and lights are all being imbued with smarts making them increasingly aware and responsive to their environment and users. This course will chart the emergence of ...more
~