Skills Dev V: Working with Networking
Made by Grace Zhu, Yulin Chen and Narayan Ashanahalli
Made by Grace Zhu, Yulin Chen and Narayan Ashanahalli
Practice developing paired devices and networked interactions with Particle.publish
Created: December 4th, 2024
In this project I worked with my team to re-make Kiss Communicator.
The Kiss Communicator connects people across distances. Users blow into it to send a "kiss" as animated light patterns. The recipient’s device signals the message, which plays once when squeezed, making each "kiss" a fleeting, meaningful gesture.
In this small prototype, we simulated the breath to light conversion and send light signals to a different device.
// This #include statement was automatically added by the Particle IDE.
#include "Particle.h"
#include <neopixel.h>
#define PIXEL_PIN SPI
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
uint16_t i;
uint32_t c = strip.Color(0, 0, 0);
int buttonPin = D2;
unsigned long lastFade = 0;
int Interval = 3000;
bool receive_or_not = false;
bool signall = true;
int breathecountreceive = 0;
int buttonState = digitalRead( buttonPin );
void setup(){
strip.begin();
strip.show();
Particle.subscribe("kissReceive", handlekiss);
Serial.begin( 9600 );
}
void handlekiss(const char *event, const char *data) {
breathecountreceive = atoi(data);
receive_or_not = true;
signall = true;
}
void loop(){
Serial.println(breathecountreceive);
Serial.println(receive_or_not);
Serial.println(buttonState);
buttonState = digitalRead( buttonPin );
// int breathecountreceive1 = atoi(data);
// if(breathecountreceive1!=breathecountreceive){
// receive_or_not = true;
// }
if(receive_or_not == true){
if (signall == true){
for(int i = 0 ;i < breathecountreceive ;i++){
unsigned long now = millis();
Secondstagebreathe1();
lastFade = now;
}
// for( i = 0;i<3;i++){
// Receivepinksignal();
// }
}
signall = false;
// else if (buttonState==LOW){
// for(i=0;i<breathecountreceive;i++){
// Secondstagebreathe();
// }
// signall = false;
// }
}
delay(500);
// receive_or_not = false;
}
void Receivepinksignal(){
for(i=0; i< strip.numPixels(); i++) {
c = strip.Color(0, 0, 255);
strip.setPixelColor(i, c );
strip.show();
delay( 5 );
}
for(i=0; i< strip.numPixels(); i++) {
c = strip.Color(0, 0, 0);
strip.setPixelColor(i, c );
strip.show();
delay( 5 );
}
}
void Secondstagebreathe(){
c = strip.Color(255, 255, 255);
unsigned long now = millis();
c = strip.Color(0, 0, 0);
if ((now - lastFade) >= Interval) {
for (int color = 0; color < 255; color++) {
for (i = 0; i < strip.numPixels(); i++) {
c = strip.Color(color, color, color);
strip.setPixelColor(i, c);
}
strip.show();
delay(5);
}
for (int color = 255; color > 0; color--) {
for (i = 0; i < strip.numPixels(); i++) {
c = strip.Color(color, color, color);
strip.setPixelColor(i, c);
}
strip.show();
delay(5);
}
lastFade = now;
}
}
void Secondstagebreathe1(){
for (int color = 0; color < 255; color++) {
for (i = 0; i < strip.numPixels(); i++) {
c = strip.Color(color, color, color);
strip.setPixelColor(i, c);
}
strip.show();
delay(5);
}
for (int color = 255; color > 0; color--) {
for (i = 0; i < strip.numPixels(); i++) {
c = strip.Color(color, color, color);
strip.setPixelColor(i, c);
}
strip.show();
delay(5);
}
}
Click to Expand
// This #include statement was automatically added by the Particle IDE.
#include "Particle.h"
#include <neopixel.h>
#define PIXEL_PIN SPI
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
uint16_t i;
uint32_t c = strip.Color(0, 0, 0);
int buttonPin = D2;
unsigned long lastFade = 0;
int Interval = 3000;
bool receive_or_not = false;
bool signall = true;
int breathecountreceive = 0;
int buttonState = digitalRead( buttonPin );
void setup(){
strip.begin();
strip.show();
Particle.subscribe("kissReceive", handlekiss);
Serial.begin( 9600 );
}
void handlekiss(const char *event, const char *data) {
breathecountreceive = atoi(data);
receive_or_not = true;
}
void loop(){
Serial.println(breathecountreceive);
Serial.println(receive_or_not);
Serial.println(buttonState);
buttonState = digitalRead( buttonPin );
if(receive_or_not == true){
if (signall == true){
for(int i = 0 ;i < breathecountreceive ;i++){
unsigned long now = millis();
Secondstagebreathe1();
lastFade = now;
}
// for( i = 0;i<3;i++){
// Receivepinksignal();
// }
}
signall = false;
// else if (buttonState==LOW){
// for(i=0;i<breathecountreceive;i++){
// Secondstagebreathe();
// }
// signall = false;
// }
}
delay(500);
}
void Receivepinksignal(){
for(i=0; i< strip.numPixels(); i++) {
c = strip.Color(0, 0, 255);
strip.setPixelColor(i, c );
strip.show();
delay( 5 );
}
for(i=0; i< strip.numPixels(); i++) {
c = strip.Color(0, 0, 0);
strip.setPixelColor(i, c );
strip.show();
delay( 5 );
}
}
void Secondstagebreathe(){
c = strip.Color(255, 255, 255);
unsigned long now = millis();
c = strip.Color(0, 0, 0);
if ((now - lastFade) >= Interval) {
for (int color = 0; color < 255; color++) {
for (i = 0; i < strip.numPixels(); i++) {
c = strip.Color(color, color, color);
strip.setPixelColor(i, c);
}
strip.show();
delay(5);
}
for (int color = 255; color > 0; color--) {
for (i = 0; i < strip.numPixels(); i++) {
c = strip.Color(color, color, color);
strip.setPixelColor(i, c);
}
strip.show();
delay(5);
}
lastFade = now;
}
}
void Secondstagebreathe1(){
for (int color = 0; color < 255; color++) {
for (i = 0; i < strip.numPixels(); i++) {
c = strip.Color(color, color, color);
strip.setPixelColor(i, c);
}
strip.show();
delay(5);
}
for (int color = 255; color > 0; color--) {
for (i = 0; i < strip.numPixels(); i++) {
c = strip.Color(color, color, color);
strip.setPixelColor(i, c);
}
strip.show();
delay(5);
}
}
Click to Expand
Practice developing paired devices and networked interactions with Particle.publish