Lights up shoes and sends steps to a person's phone over bluetooth

Dependencies:   NeoStrip mbed

Fork of NeoPixels by Allen Wild

Files at this revision

API Documentation at this revision

Comitter:
hippi345
Date:
Fri Apr 22 15:25:51 2016 +0000
Parent:
1:d235193680ab
Commit message:
final led shoes

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r d235193680ab -r 1a511cc48d0d main.cpp
--- a/main.cpp	Thu Apr 14 16:08:35 2016 +0000
+++ b/main.cpp	Fri Apr 22 15:25:51 2016 +0000
@@ -3,7 +3,7 @@
 #include "gt.h"
 #define N 64
 #define PATTERNS 3
-
+Ticker flipper;
 int hueToRGB(float h);
 
 
@@ -12,14 +12,27 @@
 RawSerial  dev(p28,p27);
 NeoStrip strip(p18, N);
 DigitalOut myled(LED1);
-DigitalIn vibration(p15); 
+InterruptIn vibration(p15); 
 Serial pc(USBTX,USBRX);
 int count = 0; 
 int senseValCur; 
 int senseValPre = 1;
-
+char bred=0;
+    char bgreen=0;
+    char bblue=0;   
 // timer used for debugging
 Timer timer;
+int hueToRGB2(int r, int g, int b);
+
+int hueToRGB2(int r, int g, int b)
+{
+    // scale to integers and return the packed value
+    uint8_t R = (uint8_t)(r);
+    uint8_t G = (uint8_t)(g);
+    uint8_t B = (uint8_t)(b);
+
+    return (R << 16) | (G << 8) | B;
+}
 
 int hueToRGB(float h)
 {
@@ -51,29 +64,12 @@
 	return (R << 16) | (G << 8) | B;
 }
 
-
-int main()
-{
-	vibration.mode(PullUp);
-	
-
-	float bright = 0.2;	// 20% is plenty for indoor use
-
-
-	strip.setBrightness(bright);	// set default brightness
-	
-	while (true)
-	{
-		strip.setBrightness(photocell);
-		myled = vibration.read();
-		senseValCur = vibration.read();
-		timer.reset(); // use a timer to measure loop execution time for debugging purposes
-		timer.start(); // for this application, the main loop takes approximately 3ms to run
-		
-		
-		if(senseValCur == 0)
-		{
-			strip.setBrightness(photocell/4);
+void flip(){
+	myled = !myled;
+	senseValCur = 0;
+	//if(senseValCur == 0)
+		//{
+		 strip.setBrightness(photocell/4);
           static float dh = 360.0 / N;
 			static float x = 0;
 
@@ -88,16 +84,70 @@
 			wait(0.01);}
           
           
-          strip.setPixels(0, N, gt_img2);
-          strip.write();
-        	wait(.005);
+          for (int i = 0; i < N; i++)
+            {strip.setPixel(i, hueToRGB2(bred,bgreen,bblue)); //blue red green
+
+    
+            x += 1;
+            if (x > 360)
+            x = 0;
+            strip.write();
+            wait(0.01);}
             count++;
         pc.printf("%i\n\r",count);
         dev.printf("%i\n\r",count);
+        //senseValCur = 1;
+        //}
+        senseValPre = senseValCur;	
+}
+int main()
+{
+	vibration.mode(PullUp);
+	int set = 0;
+	float bright = 0.2;	// 20% is plenty for indoor use
+  //flipper.attach(&flip,5);	
+   // while(set < 4){
+    	
+		//set++;
+		//}
+	
+	strip.setBrightness(bright);	// set default brightness
+	while (true)
+	{
+		vibration.rise(&flip);
+		strip.setBrightness(photocell);
+		//myled = vibration.read();
+		//myled = !myled;
+		//senseValCur = vibration.read();
+		timer.reset(); // use a timer to measure loop execution time for debugging purposes
+		timer.start(); // for this application, the main loop takes approximately 3ms to run
+		 if (dev.getc()=='!') {
+            if (dev.getc()=='C') { //color data packet
+                bred = dev.getc(); // RGB color values
+                bgreen = dev.getc();
+                bblue = dev.getc();
+            
+                if (dev.getc()==char(~('!' + 'C' + bred + bgreen + bblue))) {
+                   static float x = 0;
+
+            for (int i = 0; i < N; i++)
+            {strip.setPixel(i, hueToRGB2(bred,bgreen,bblue)); //blue red green
+
+    
+            x += 1;
+            if (x > 360)
+            x = 0;
+            strip.write();
+            wait(0.01);}
+             
+                }
         }
-        senseValPre = senseValCur;		
 		}
+		
+		
+        
 	}
+}