Demo for lamp

Dependencies:   C12832_lcd PixelArray WS2812 mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
cathal66
Date:
Thu Apr 23 15:56:42 2015 +0000
Commit message:
Demo for lamp

Changed in this revision

C12832_lcd.lib Show annotated file Show diff for this revision Revisions of this file
PixelArray.lib Show annotated file Show diff for this revision Revisions of this file
WS2812.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 2cf2aa8c0d7c C12832_lcd.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Thu Apr 23 15:56:42 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
diff -r 000000000000 -r 2cf2aa8c0d7c PixelArray.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PixelArray.lib	Thu Apr 23 15:56:42 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/chris/code/PixelArray/#b45a70faaa83
diff -r 000000000000 -r 2cf2aa8c0d7c WS2812.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WS2812.lib	Thu Apr 23 15:56:42 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/bridadan/code/WS2812/#6e647820f587
diff -r 000000000000 -r 2cf2aa8c0d7c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Apr 23 15:56:42 2015 +0000
@@ -0,0 +1,368 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "WS2812.h"
+#include "PixelArray.h" 
+ 
+#define WS2812_BUF 10
+#define NUM_COLORS 1
+#define NUM_LEDS_PER_COLOR 10
+PixelArray px(WS2812_BUF);
+
+// See the program page for information on the timing numbers
+// The given numbers are for the K64F
+WS2812 ws(p9, WS2812_BUF, 5, 10, 10, 15);
+
+PwmOut Servo_Y(p22);
+PwmOut Servo_X(p21);
+PwmOut Servo_Z(p23);
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+ 
+float Servo_z_smooth;
+
+void Servo_Z_Thread(void const *args) {
+    float Sevro_Pos;
+    float Sevro_Pos_New = 0.1;
+    float Sevro_Pos_Old = 0.01;
+    
+    while (true) {
+        
+        Sevro_Pos_New = Servo_z_smooth;
+        
+        if(Sevro_Pos_Old <= Sevro_Pos_New)
+            {
+            for(float i=Sevro_Pos_Old*10000; i<=Sevro_Pos_New*10000; i=i+25)
+                {
+                Sevro_Pos = i/10000;
+                Servo_Z = Sevro_Pos;
+                pc.printf("Servo_Z1: %1.6f %1.6f %1.6f\n\r ",Sevro_Pos, i,Sevro_Pos_Old);
+                //Thread::wait(50);
+                }
+            }
+        else
+            {
+            for(float i=Sevro_Pos_Old*10000; i>=Sevro_Pos_New*10000; i=i-25)
+                {
+                Sevro_Pos = i/10000;
+                Servo_Z = Sevro_Pos;
+                pc.printf("Servo_Z2: %1.6f \n\r",Sevro_Pos);
+                //Thread::wait(50);
+                }            
+            }
+        Sevro_Pos_Old = Sevro_Pos_New;
+        Thread::wait(500);
+    }    
+}
+ 
+ 
+ 
+void LED_All_Colour(int red , int green ,int blue , int bright)
+    {
+    ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling
+    
+    int colorbuf[NUM_COLORS] = {0x000000};
+    //int colorbuf[NUM_COLORS] = {0x000000,0x00f0ff,0x00ff00,0x00ffff,0xffffff,0x00ff00,0x00ffff,0x0000ff,0xff00ff};
+    
+    red <<= 16;
+    green <<= 8;
+    
+    colorbuf[0] = red + green + blue;
+    
+    pc.printf("Colour: %6x red:%6x  Green:%6x  Blue:%6x Bright:%x \n\r",colorbuf[0], red , green , blue, bright);
+    // for each of the colours (j) write out 10 of them
+    // the pixels are written at the colour*10, plus the colour position
+    // all modulus 60 so it wraps around
+    for (int i = 0; i < WS2812_BUF; i++) {
+        px.Set(i, colorbuf[(i / NUM_LEDS_PER_COLOR) % NUM_COLORS]);
+    }
+    
+    // now all the colours are computed, add a fade effect using intensity scaling
+    // compute and write the II value for each pixel
+    for (int j=0; j<WS2812_BUF; j++) {
+        // px.SetI(pixel position, II value)
+        //px.SetI(j%WS2812_BUF, 0xff+(0xf*(j%NUM_LEDS_PER_COLOR)));     //full brightness
+        px.SetI(j%WS2812_BUF, bright +(bright*(j%NUM_LEDS_PER_COLOR)));        //control brightness    
+    }
+    //set the colour of the LEDs
+    for (int z=WS2812_BUF; z >= 0 ; z--) {
+        ws.write_offsets(px.getBuf(),z,z,z);
+        
+
+        }    
+}
+
+
+void LED_Colour_Pos(int position, int red , int green ,int blue , int bright)
+    {
+    ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling
+    
+    int colorbuf = 0x000000;
+    
+    red <<= 16;
+    green <<= 8;
+    
+    colorbuf = red + green + blue;
+    
+    pc.printf("Colour: %6x red:%6x  Green:%6x  Blue:%6x Bright:%x \n\r",colorbuf, red , green , blue, bright);
+    // for each of the colours (j) write out 10 of them
+    // the pixels are written at the colour*10, plus the colour position
+    // all modulus 60 so it wraps around
+    px.Set(position, colorbuf);
+    
+    // now all the colours are computed, add a fade effect using intensity scaling
+    // compute and write the II value for each pixel
+    //px.SetI(pixel position, II value)
+    px.SetI(position, bright);        //control brightness    
+}
+
+void LED_Colour_Pos_Set()
+{
+    //set the colour of the LEDs
+    for (int z=WS2812_BUF-1; z >= 0 ; z--) 
+    {
+        ws.write_offsets(px.getBuf(),z,z,z);
+    } 
+}
+
+
+void Smooth_Fade(int h , int speed)
+{
+   for(int j = 0; j<=h;j++)
+    {
+        for(int i = 0;i<=255;i=i+speed)
+        {
+            LED_All_Colour(i, 0 ,255-i , 255);
+            //wait(0.01);
+        }    
+        for(int i = 0;i<=255;i=i+speed)
+        {
+            LED_All_Colour(255-i, i ,0 , 255);
+            //wait(0.01);
+        } 
+        for(int i = 0;i<=255;i=i+speed)
+        {
+            LED_All_Colour(0, 255-i ,i , 255);
+            //wait(0.01);
+        } 
+    }  
+}
+
+
+void Red_Blue_Flash(int h)
+{
+   for(int i = 0;i<=h;i++)
+        {
+            
+            LED_All_Colour(255, 0 ,0 , 50);
+            wait(0.02);
+            LED_All_Colour(255, 0 ,0 , 255);
+            wait(0.02);
+            LED_All_Colour(0, 0 , 255 , 50);
+            wait(0.02);            
+            LED_All_Colour(0, 0 , 255 , 255);
+            wait(0.02);
+        }   
+}
+
+ 
+int main() {
+    Thread thread_Servo_Z(Servo_Z_Thread );
+                
+    
+    while (true) {
+       /////////////////////////////////////////////////////////////////////////////////////
+       ////////////////////////////////////   X   //////////////////////////////////////////
+       /////////////////////////////////////////////////////////////////////////////////////
+        Servo_Y = 0.05;
+        Servo_X = 0.06;
+        Servo_z_smooth = 0.01;
+        LED_Colour_Pos(0,255,0,0,128);
+        LED_Colour_Pos(1,0,255,0,128);
+        LED_Colour_Pos(2,0,0,255,128);
+        LED_Colour_Pos(3,255,255,0,128);  
+        LED_Colour_Pos(4,255,0,255,128); 
+        LED_Colour_Pos(5,128,255,0,128);
+        LED_Colour_Pos(6,128,50,0,255);
+        LED_Colour_Pos(7,0,255,128,128);
+        LED_Colour_Pos(8,128,0,128,255);  
+        LED_Colour_Pos(9,128,128,255,128); 
+        LED_Colour_Pos_Set();        
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4 \n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(1000);
+        Servo_Y = 0.05;
+        Servo_X = 0.06;
+        Servo_z_smooth = 0.05;
+        LED_Colour_Pos(0,128,255,0,128);
+        LED_Colour_Pos(1,128,50,0,255);
+        LED_Colour_Pos(2,0,255,128,128);
+        LED_Colour_Pos(3,128,0,128,255);  
+        LED_Colour_Pos(4,128,128,255,128); 
+        LED_Colour_Pos(5,255,255,0,255);
+        LED_Colour_Pos(6,128,50,127,255);
+        LED_Colour_Pos(7,255,255,0,128);
+        LED_Colour_Pos(8,128,0,128,255);  
+        LED_Colour_Pos(9,0,128,255,128);         
+        LED_Colour_Pos_Set();         
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500);
+        Servo_Y = 0.05;
+        Servo_X = 0.08;
+        Servo_z_smooth = 0.08;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500); 
+        Servo_Y = 0.06;
+        Servo_X = 0.05;
+        Servo_z_smooth = 0.1;
+        LED_All_Colour(255, 0 , 0 , 255);
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500); 
+        Servo_Y = 0.05;
+        Servo_X = 0.05;
+        Servo_z_smooth = 0.05;
+        LED_All_Colour(255, 255 , 0 , 255);        
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500); 
+        Servo_Y = 0.05;
+        Servo_X = 0.09;
+        Servo_z_smooth = 0.05;
+        LED_All_Colour(0, 0 , 255 , 255);        
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500); 
+        Servo_Y = 0.05;
+        Servo_X = 0.05;
+        Servo_z_smooth = 0.05;
+        LED_All_Colour(0, 255 , 0 , 255);        
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500);     
+        Servo_Y = 0.05;
+        Servo_X = 0.09;
+        Servo_z_smooth = 0.05;
+        LED_Colour_Pos(0,255,0,0,128);
+        LED_Colour_Pos(1,0,255,0,128);
+        LED_Colour_Pos(2,0,0,255,128);
+        LED_Colour_Pos(3,255,255,0,128);  
+        LED_Colour_Pos(4,255,0,255,128); 
+        LED_Colour_Pos(5,128,255,0,128);
+        LED_Colour_Pos(6,128,50,0,255);
+        LED_Colour_Pos(7,0,255,128,128);
+        LED_Colour_Pos(8,128,0,128,255);  
+        LED_Colour_Pos(9,128,128,255,128); 
+        LED_Colour_Pos_Set(); 
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500); 
+        Servo_Y = 0.05;
+        Servo_X = 0.05;
+        Servo_z_smooth = 0.05;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500);  
+        Servo_Y = 0.05;
+        Servo_X = 0.08;
+        Servo_z_smooth = 0.05;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500); 
+        
+       /////////////////////////////////////////////////////////////////////////////////////
+       ////////////////////////////////////   y   //////////////////////////////////////////
+       /////////////////////////////////////////////////////////////////////////////////////
+        Servo_Y = 0.055;
+        Servo_X = 0.08;
+        Servo_z_smooth = 0.05;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500);   
+        Servo_Y = 0.08;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.05;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500); 
+        Servo_Y = 0.055;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.05;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500); 
+        Servo_Y = 0.065;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.05;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(1000); 
+        Servo_Y = 0.055;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.05;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500);   
+        Servo_Y = 0.065;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.05;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500); 
+        Servo_Y = 0.055;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.05;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500);  
+        Servo_Y = 0.065;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.05;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500); 
+        Servo_Y = 0.06;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.09;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(750);                             
+        
+        /////////////////////////////////////////////////////////////////////////////////////
+        ////////////////////////////////////   Z   //////////////////////////////////////////
+        /////////////////////////////////////////////////////////////////////////////////////
+        Servo_Y = 0.06;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.08;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500);  
+        Servo_Y = 0.06;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.1;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500);                             
+        Servo_Y = 0.06;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.07;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(500);
+        Servo_Y = 0.06;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.11;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(750); 
+        Servo_Y = 0.06;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.07;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(750);  
+        Servo_Y = 0.06;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.11;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(750);                             
+        Servo_Y = 0.06;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.07;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(750);
+        Servo_Y = 0.06;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.11;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(750);                            
+        Servo_Y = 0.06;
+        Servo_X = 0.075;
+        Servo_z_smooth = 0.07;
+        printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(1500);                          
+        Servo_Y = 0.06;
+        Servo_X = 0.75;
+        Servo_z_smooth = 0.03;
+        printf("Servo X: %f1.4 Servo Y: %f1.4 Servo Z: %f1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
+        Thread::wait(1500);                    
+    }
+}
diff -r 000000000000 -r 2cf2aa8c0d7c mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Thu Apr 23 15:56:42 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#721c3a93a7b8
diff -r 000000000000 -r 2cf2aa8c0d7c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Apr 23 15:56:42 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889
\ No newline at end of file