rsp to mbed

Dependencies:   mbed neopixels_spi

Fork of RSP_receivefunction by Mfonobong Ekanem

main.cpp

Committer:
el12moe
Date:
2015-05-13
Revision:
1:bcb384b83f54
Parent:
0:3f93f42809e5

File content as of revision 1:bcb384b83f54:

#include "mbed.h"

#include "neopixels_spi.h"

DigitalOut myled(LED1);
neopixels_spi lights;
Ticker xmas;

Serial pi(USBTX, USBRX);// Initialse USB serial port
void mbedReceive(void);
void modeActivated(void);
void security(void);
void brightness(void);
void colour(void);
void festive(void);
void sleep(void);
void presetBrightness(void);
void presetColour(void);
void christmas(void);
void hunika(void);
void akwansa(void);
void rainbow(void);
void rgbm(void);
void christmas2(void);
void hunika2(void);
void akwansa2(void);
void rainbow2(void);
void rgbm2(void);

//RSP packets dependencies
int room=0;
int mode=0;
int red=0;
int green=0;
int blue=0;

//lights mode dependencies 
int rg[8][3] = {{255,0,0},{0,255,0},{255,0,0},{0,255,0},{255,0,0},{0,255,0},{255,0,0},{0,225,0}};
int gr[8][3] = {{0,255,0},{255,0,0},{0,255,0},{255,0,0},{0,255,0},{255,0,0},{0,225,0},{255,0,0}};

int bw[8][3] = {{0,0,255},{255,255,255},{0,0,255},{255,255,255},{0,0,255},{255,255,255},{0,0,255},{255,255,255}};
int wb[8][3] = {{255,255,255},{0,0,255},{255,255,255},{0,0,255},{255,255,255},{0,0,255},{255,255,255},{0,0,255}};

int rgb[8][3] = {{255,0,0},{0,255,0},{0,0,255},{255,0,0},{0,255,0},{0,0,255},{255,0,0},{0,255,0}};
int brg[8][3] = {{0,0,255},{255,0,0},{0,255,0},{0,0,255},{255,0,0},{0,255,0},{0,0,255},{255,0,0}};
int gbr[8][3] = {{0,255,0},{0,0,255},{255,0,0},{0,255,0},{0,0,255},{255,0,0},{0,255,0},{0,0,255}};
int bgr[8][3] = {{0,0,255},{0,255,0},{255,0,0},{0,0,255},{0,255,0},{255,0,0},{0,0,255},{0,255,0}};

int ak1[8][3] = {{255,0,0},{0,255,0},{0,0,0},{255,0,0},{0,255,0},{0,0,0},{255,0,0},{0,255,0}};
int ak2[8][3] = {{0,0,0},{255,0,0},{0,255,0},{0,0,0},{255,0,0},{0,255,0},{0,0,0},{255,0,0}};
int ak3[8][3] = {{0,255,0},{0,0,0},{255,0,0},{0,255,0},{0,0,0},{255,0,0},{0,255,0},{0,0,0}};
int ak4[8][3] = {{0,0,0},{0,255,0},{255,0,0},{0,0,0},{0,255,0},{255,0,0},{0,0,0},{0,255,0}};

int ra1[8][3] = {{255,0,0},{255,165,0},{255,255,0},{255,255,255},{0,255,0},{0,0,255},{75,0,255},{238,130,238}};
int ra2[8][3] = {{255,165,0},{255,255,0},{255,255,255},{0,255,0},{0,0,255},{75,0,255},{238,130,238},{255,0,0}};
int ra3[8][3] = {{255,255,0},{255,255,255},{0,255,0},{0,0,255},{75,0,255},{238,130,238},{255,0,0},{255,165,0}};
int ra4[8][3] = {{255,255,255},{0,255,0},{0,0,255},{75,0,255},{238,130,238},{255,0,0},{255,165,0},{255,255,0}};
int ra5[8][3] = {{0,255,0},{0,0,255},{75,0,255},{238,130,238},{255,0,0},{255,165,0},{255,255,0},{255,255,255}};
int ra6[8][3] = {{0,0,255},{75,0,255},{238,130,238},{255,0,0},{255,165,0},{255,255,0},{255,255,255},{0,255,0}};
int ra7[8][3] = {{75,0,255},{238,130,238},{255,0,0},{255,165,0},{255,255,0},{255,255,255},{0,255,0},{0,0,255}};
int ra8[8][3] = {{238,130,238},{255,0,0},{255,165,0},{255,255,0},{255,255,255},{0,255,0},{0,0,255},{75,0,255}};


int main() {
    while(1) {
        if(pi.readable()){
         modeActivated();
         //mbedReceive();   
            }
    }
}

// function to receive stuff from pi 
void mbedReceive(void){
    int section = pi.getc();
    if (section==1){
        security(); //activate security mode
        }
    else if (section==2){
        room = pi.getc();
        mode = pi.getc();
        red = pi.getc();
        green = pi.getc();
        blue = pi.getc();
        }
    else if (section==0){
        //normal lights function a way of stopping different light modes
        // b2() stop alarm
        room = pi.getc();
        if (room==1){
            //normal mode 1
            }
        else if (room==2){
            //normal mode 2
            }
        
        }
    }
    
void modeActivated(void){
    mbedReceive(); 
     if (mode==1){
      brightness();
        }
     if (mode==2){
      colour();
        }
     if (mode==3){
      festive();
        } 
     if (mode==4){
      sleep();
        }
     if (mode==5){
     presetBrightness();
        }
     if (mode==6){
      presetColour();
        }
            
    }

 void security(void){
     
     }

void brightness(void){
    if (room==1){
       lights.setRGBStrip1(red, red, red);
        }
     if (room==2){
      lights.setRGBStrip2(red, red, red);
        }
    }
void colour(void){
    if (room==1){
     lights.setRGBStrip1(red, green, blue);
        }
     if (room==2){
     lights.setRGBStrip2(red, green, blue);
        }
    
    }
void festive(void){
    if (room==1){
        if(red==1){
         christmas();  
        }
        if(red==2){
         hunika();   
        }
        if(red==3){
         akwansa();   
        }
        if(red==4){
         rainbow();   
        }
        if(red==5){
         rgbm();   
        }
        }
     else if (room==2){
        if(red==1){
         
         christmas2();   
        }
        if(red==2){
         hunika2();   
        }
        if(red==3){
         akwansa2();   
        }
        if(red==4){
         rainbow2();   
        }
        if(red==5){
         rgbm2();   
        }
        }
    }
void sleep(void){
    if (room==1){
     //  setRGBStrip1(red, green, blue); sleep pattern for strip1
        }
     if (room==2){
     //  setRGBStrip2(red, green, blue);sleep pattern for strip1
        }
    }
void presetBrightness(void){
    
    }
void presetColour(void){
    
    }
    
//xmas red & green 
void christmas(void){
    lights.setRGBPixels1(rg);
      wait(1);
    lights.setRGBPixels1(gr);
      wait(1);
    lights.setRGBPixels1(rg);
      wait(1);
    lights.setRGBPixels1(gr);
      wait(1);
    lights.setRGBPixels1(rg);
      wait(1);
    lights.setRGBPixels1(gr);
      wait(1);
    lights.setRGBPixels1(rg);
      wait(1);
    lights.setRGBPixels1(gr);
      wait(1);
    lights.setRGBPixels1(rg);
      wait(1);
    lights.setRGBPixels1(gr);
      wait(1);
    lights.setRGBStrip1(255, 0, 0);
         wait(1);
    lights.setRGBStrip1(0,255,0);
         wait(1);
    }
void hunika(void){
     lights.setRGBPixels1(bw);
      wait(1);
     lights.setRGBPixels1(wb);
      wait(1);
      lights.setRGBPixels1(bw);
      wait(1);
     lights.setRGBPixels1(wb);
      wait(1);
      lights.setRGBPixels1(bw);
      wait(1);
     lights.setRGBPixels1(wb);
      wait(1);
      lights.setRGBPixels1(bw);
      wait(1);
     lights.setRGBPixels1(wb);
      wait(1);
      lights.setRGBPixels1(bw);
      wait(1);
     lights.setRGBPixels1(wb);
      wait(1);
     lights.setRGBStrip1(0, 0, 255);
         wait(1);
    lights.setRGBStrip1(255,255,255);
         wait(1);
    }
    
void akwansa(void){
    lights.setRGBPixels1(ak1);
      wait(1);
     lights.setRGBPixels1(ak2);
      wait(1);
      lights.setRGBPixels1(ak3);
      wait(1);
     lights.setRGBPixels1(ak4);
      wait(1);
      lights.setRGBPixels1(ak1);
      wait(1);
     lights.setRGBPixels1(ak2);
      wait(1);
      lights.setRGBPixels1(ak3);
      wait(1);
     lights.setRGBPixels1(ak4);
      wait(1);
      lights.setRGBPixels1(ak1);
      wait(1);
     lights.setRGBPixels1(ak2);
      wait(1);
      lights.setRGBPixels1(ak3);
      wait(1);
     lights.setRGBPixels1(ak4);
      wait(1);
    }
void rainbow(void){
     lights.setRGBPixels1(ra1);
      wait(1);
     lights.setRGBPixels1(ra2);
      wait(1);
      lights.setRGBPixels1(ra3);
      wait(1);
     lights.setRGBPixels1(ra4);
      wait(1);
      lights.setRGBPixels1(ra5);
      wait(1);
     lights.setRGBPixels1(ra6);
      wait(1);
      lights.setRGBPixels1(ra7);
      wait(1);
     lights.setRGBPixels1(ra8);
      wait(1);
    }
    
void rgbm(void){
    lights.setRGBPixels2(rgb);
      wait(1);
     lights.setRGBPixels2(brg);
      wait(1);
      lights.setRGBPixels2(gbr);
      wait(1);
     lights.setRGBPixels2(bgr);
      wait(1);
      lights.setRGBPixels2(rgb);
      wait(1);
     lights.setRGBPixels2(brg);
      wait(1);
      lights.setRGBPixels2(gbr);
      wait(1);
     lights.setRGBPixels2(bgr);
      wait(1);
      lights.setRGBPixels2(rgb);
      wait(1);
     lights.setRGBPixels2(brg);
      wait(1);
      lights.setRGBPixels2(gbr);
      wait(1);
     lights.setRGBPixels2(bgr);
      wait(1);
     lights.setRGBStrip2(255, 0, 0);
         wait(1);
    lights.setRGBStrip2(0,255,0);
         wait(1);
    lights.setRGBStrip2(0,0,255);
         wait(1);
    }
    
void christmas2(void){
    lights.setRGBPixels2(rg);
      wait(1);
     lights.setRGBPixels2(gr);
      wait(1);
      lights.setRGBPixels2(rg);
      wait(1);
     lights.setRGBPixels2(gr);
      wait(1);
      lights.setRGBPixels2(rg);
      wait(1);
     lights.setRGBPixels2(gr);
      wait(1);
      lights.setRGBPixels2(rg);
      wait(1);
     lights.setRGBPixels2(gr);
      wait(1);
      lights.setRGBPixels2(rg);
      wait(1);
     lights.setRGBPixels2(gr);
      wait(1);
     lights.setRGBStrip2(255, 0, 0);
         wait(1);
    lights.setRGBStrip2(0,255,0);
         wait(1);
    }
    
void hunika2(void){
     lights.setRGBPixels2(bw);
      wait(1);
     lights.setRGBPixels2(wb);
      wait(1);
      lights.setRGBPixels2(bw);
      wait(1);
     lights.setRGBPixels2(wb);
      wait(1);
      lights.setRGBPixels2(bw);
      wait(1);
     lights.setRGBPixels2(wb);
      wait(1);
      lights.setRGBPixels2(bw);
      wait(1);
     lights.setRGBPixels2(wb);
      wait(1);
      lights.setRGBPixels2(bw);
      wait(1);
     lights.setRGBPixels2(wb);
      wait(1);
     lights.setRGBStrip2(0, 0, 255);
         wait(1);
    lights.setRGBStrip2(255,255,255);
         wait(1);
    }
    
void akwansa2(void){
    lights.setRGBPixels2(ak1);
      wait(1);
     lights.setRGBPixels2(ak2);
      wait(1);
      lights.setRGBPixels2(ak3);
      wait(1);
     lights.setRGBPixels2(ak4);
      wait(1);
      lights.setRGBPixels2(ak1);
      wait(1);
     lights.setRGBPixels2(ak2);
      wait(1);
      lights.setRGBPixels2(ak3);
      wait(1);
     lights.setRGBPixels2(ak4);
      wait(1);
      lights.setRGBPixels2(ak1);
      wait(1);
     lights.setRGBPixels2(ak2);
      wait(1);
      lights.setRGBPixels2(ak3);
      wait(1);
     lights.setRGBPixels2(ak4);
      wait(1);
    }
    
    
void rainbow2(void){
     lights.setRGBPixels2(ra1);
      wait(1);
     lights.setRGBPixels2(ra2);
      wait(1);
      lights.setRGBPixels2(ra3);
      wait(1);
     lights.setRGBPixels2(ra4);
      wait(1);
      lights.setRGBPixels2(ra5);
      wait(1);
     lights.setRGBPixels2(ra6);
      wait(1);
      lights.setRGBPixels2(ra7);
      wait(1);
     lights.setRGBPixels2(ra8);
      wait(1);
    }
    
    
void rgbm2(void){
    lights.setRGBPixels2(rgb);
      wait(1);
     lights.setRGBPixels2(brg);
      wait(1);
      lights.setRGBPixels2(gbr);
      wait(1);
     lights.setRGBPixels2(bgr);
      wait(1);
      lights.setRGBPixels2(rgb);
      wait(1);
     lights.setRGBPixels2(brg);
      wait(1);
      lights.setRGBPixels2(gbr);
      wait(1);
     lights.setRGBPixels2(bgr);
      wait(1);
     lights.setRGBPixels2(rgb);
      wait(1);
     lights.setRGBPixels2(brg);
      wait(1);
     lights.setRGBPixels2(gbr);
      wait(1);
     lights.setRGBPixels2(bgr);
      wait(1);
     lights.setRGBStrip2(255, 0, 0);
         wait(1);
    lights.setRGBStrip2(0,255,0);
         wait(1);
    lights.setRGBStrip2(0,0,255);
         wait(1);
    }