NeoStrip

Dependencies:   NeoStrip mbed

Fork of NeoPixels by Allen Wild

Revision:
1:a0c08e317195
Parent:
0:f38492690f0e
--- a/main.cpp	Wed Mar 12 18:41:42 2014 +0000
+++ b/main.cpp	Sun Jul 02 08:47:49 2017 +0000
@@ -14,6 +14,7 @@
 #define N 64
 #define PATTERNS 3
 
+Serial pc(USBTX, USBRX);
 int hueToRGB(float h);
 void pattern0();
 void pattern1();
@@ -22,23 +23,23 @@
 // array of function pointers to the various patterns
 void (*patterns[])(void) = {&pattern0, &pattern1, &pattern2};
 
-NeoStrip strip(p18, N);
-DigitalIn b1(p20); // brightness up
+NeoStrip strip(p21, N);
+int selekt=0;
+/*DigitalIn b1(p20); // brightness up
 DigitalIn b2(p19); // brightness down
-DigitalIn b3(p21); // next pattern
+DigitalIn b3(p21); // next pattern*/
 
 // timer used for debugging
 Timer timer;
 
 int main()
 {
-	b1.mode(PullDown);
-	b2.mode(PullDown);
-	b3.mode(PullDown);
+    pc.baud(115200);
+    printf("Test af LED\r\n");   	
 	
 	int pattern = 0;
 	float bright = 0.2;	// 20% is plenty for indoor use
-	bool b3o = b3;		// old copy of button 3 to poll for changes
+	int b3o = selekt;		// old copy of button 3 to poll for changes
 
 	strip.setBrightness(bright);	// set default brightness
 	
@@ -48,7 +49,7 @@
 		timer.start(); // for this application, the main loop takes approximately 3ms to run
 
 		// button 1 increases brightness
-		if (b1 && bright < 1)
+		if ((selekt==1) && bright < 1)
 		{
 			bright += 0.01;
 			if (bright > 1)
@@ -57,7 +58,7 @@
 		}
 
 		// button 2 decreases brightness
-		if (b2 && bright > 0)
+		if ((selekt==2) && bright > 0)
 		{
 			bright -= 0.01;
 			if (bright < 0)
@@ -66,22 +67,25 @@
 		}
 		
 		// button 3 changes the pattern, only do stuff when its state has changed
-		if (b3 != b3o)
+		if ((selekt==3) != b3o)
 		{
-			if (b3 && ++pattern == PATTERNS)
-				pattern = 0;
-			b3o = b3;
+			if (++pattern == PATTERNS) pattern = 0;
+
 		}
-		
+		selekt=0;
 		// run the pattern update function which sets the strip's pixels
 		patterns[pattern]();
 		strip.write();
 
 		timer.stop();
 		// print loop time if b3 is pressed
-		if (b3)
-			printf("Loop Time: %dus\n", timer.read_us());
-		
+        if (pc.readable()) {
+            switch(pc.getc()) {
+            case '1': selekt=1; break;	
+            case '2': selekt=2; break;	
+            case '3': selekt=3; break;	
+           } 	
+        }		
 		wait_ms(10);
 	}
 }