//Sensor Variables
//Functional
//
//Fidget
//Analog
//Roll:GyroScope
int rollPin=A0;
//Flick: Flex Bend
int flickPin=A1;
//Wiggle: Joystick
int wiggleXPin=A3;
int wiggleYPin=A4;
//Smooth: Pressure Sensor
int smoothPin=A5;
//Digital
//Wiggle cont'd
int wiggleSWPin=D0;
//Toggle on off button//| Slide: 2 way switch (not a toggle button)
int togglePin=D1;
//Click: tactile button group
int clickPin1=D2;
int clickPin2=D3;
int clickPin3=D4;
int clickPin4=D5;
int clickPin5=D6;
//Particle Variables
//raw data values
int rollValue;
int wiggleXValue;
int wiggleYValue;
int wiggleSWValue;
int flickValue;
int clickValue;
int toggleValue;
int smoothValue;
//count variables
int rollCount=0;
int wiggleTime=0;
int wiggleClickCount=0;
int flickTime=0;
int clickTotal=0;
int toggleTotal=0;
int smoothTime=0;
void setup() {
pinMode(rollPin, INPUT);
pinMode(flickPin, INPUT);
pinMode(wiggleXPin, INPUT);
pinMode(wiggleYPin, INPUT);
pinMode(wiggleSWPin, INPUT);
pinMode(togglePin, INPUT);
pinMode(smoothPin, INPUT);
pinMode(clickPin1, INPUT);
pinMode(clickPin2, INPUT);
pinMode(clickPin3, INPUT);
pinMode(clickPin4, INPUT);
pinMode(clickPin5, INPUT);
Particle.variable("cRoll",&rollValue, INT);
Particle.variable("cFlick",&flickValue, INT);
Particle.variable("cWiggleX",&wiggleXValue, INT);
Particle.variable("cWiggleY",&wiggleXValue, INT);
Particle.variable("cWiggleSW",&wiggleSWValue, INT);
Particle.variable("cToggle",&toggleValue, INT);
Particle.variable("cSmooth",&smoothValue, INT);
Particle.variable("cClick",&clickTotal, INT);
Particle.variable("flickTime",&flickTime, INT);
Particle.variable("wiggleTime",&wiggleTime, INT);
Particle.variable("wiggleClkTtl",&wiggleSWValue, INT);
Particle.variable("toggleTotal",&toggleTotal, INT);
Particle.variable("smoothTime",&smoothTime, INT);
Particle.variable("clickTotal",&clickTotal, INT);
}
void loop() {
// checkRoll: publishes raw data
checkRoll();
//delay(1000);
//check wiggle: publishes raw data; unidentified issue with switch on and off 5V?
checkWiggle();
//delay(1000);
//check flick: publishes raw data
checkFlick();
//delay(1000);
//check click: Untested
checkClick();
//check toggle: publishes raw data; unidentified issu See long comment below
checkToggle();
//delay(1000);
// //check smooth: publishes raw data when other sensors aren't publish; unidentified issu See long comment below
checkSmooth();
delay(2000);
/*
Toggle/Smooth Test error:
{"device":{"system":{"uptime":188,"memory":{"total":171272,"used":85304}},"cloud":{"connection":{"status":1,"error":17,"attempts":1,"disconnect":1},"disconnects":2,"publish":{"rate_limited":0},"coap":{"unack":8}}},"service":{"device":{"status":"ok"},"coap":{"round_trip":43},"cloud":{"uptime":0,"publish":{"sent":0}}}}
*/
//delay to account for human speed's inadequacies
//delay(5000);
}
void checkRoll(){
rollValue = analogRead(rollPin);
//Particle.publish("roll value is :", (String)rollValue);
//delay(500)
//Record Roll time and
//Record Roll rate
//Record total rolles
//Store roll data to a day file at 11:59:59 and reset
//return 1;
}
void checkWiggle(){
wiggleXValue = analogRead(wiggleXPin);
int wiggleYValue = analogRead(wiggleYPin);
int wiggleSWValue = digitalRead(wiggleSWPin);
String wiggleValues = (String)wiggleXValue;
wiggleValues+= ", ";
wiggleValues+= (String)wiggleYValue;
wiggleValues+= ", ";
wiggleValues+= (String)wiggleSWValue;
//Particle.publish("wiggle values are :", wiggleValues);
//delay(500);
//Record Wiggle time and
//Record Wiggle rate
//Record total Wiggles
//Store wiggle data to a day file at 11:59:59 and reset
//return 1;
}
void checkFlick(){
flickValue = analogRead(flickPin);
//Particle.publish("flick value is :", (String)flickValue);
//delay(500);
//Record Flick time and
//Record Flick rate
//Record total Flicks
if (flickValue < 4050) flickTime+=2000;
//Store flick data to a day file at 11:59:59 and reset
//return 1;
}
void checkClick(){
int clickValue1 = digitalRead(clickPin1);
int clickValue2 = digitalRead(clickPin2);
int clickValue3 = digitalRead(clickPin3);
int clickValue4 = digitalRead(clickPin4);
int clickValue5 = digitalRead(clickPin5);
int cClickTotal = clickValue1 + clickValue2 + clickValue3 + clickValue4 + clickValue5;
if (cClickTotal>0) clickValue = 1;
else clickValue = 0;
//Particle.publish("total click value is :", (String)clickTotal);
//delay(1000);
//Record Click time and
//Record Click rate
//Record total Clicks
clickTotal+=cClickTotal;
//Store click data to a day file at 11:59:59 and reset
//return 1;
}
void checkToggle(){
if (toggleValue!= digitalRead(togglePin)) toggleTotal++;
toggleValue = digitalRead(togglePin);
//Particle.publish("toggle value is :", (String)toggleValue);
//delay(1000);
//Record Glide time and
//Record Glide rate
//Record total Glides
//Store glide data to a day file at 11:59:59 and reset
//return 1;
}
void checkSmooth(){
smoothValue = analogRead(smoothPin);
//Particle.publish("smooth value is :", (String)smoothValue);
//delay(1000);
//Record Smooth time and
if (smoothValue > 250) {
smoothTime=smoothTime + 2000;
}
//Record Smooth rate
//Record total smooths
//Store smooth data to a day file at 11:59:59 and reset
//return 1;
}
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. .