final code

Dependencies:   mbed neopixels_spi

Committer:
el12moe
Date:
Thu May 14 00:25:55 2015 +0000
Revision:
0:437b83685196
new

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el12moe 0:437b83685196 1 #include "mbed.h"
el12moe 0:437b83685196 2
el12moe 0:437b83685196 3 #include "neopixels_spi.h"
el12moe 0:437b83685196 4
el12moe 0:437b83685196 5 neopixels_spi lights;
el12moe 0:437b83685196 6 Ticker xmas;
el12moe 0:437b83685196 7
el12moe 0:437b83685196 8 Serial xbee(p9,p10); //Initalise xbee_lib
el12moe 0:437b83685196 9
el12moe 0:437b83685196 10 Serial pi(USBTX, USBRX);// Initialse USB serial port
el12moe 0:437b83685196 11 void mbedReceive(void);
el12moe 0:437b83685196 12 void modeActivated(void);
el12moe 0:437b83685196 13 void security(void);
el12moe 0:437b83685196 14 void brightness(void);
el12moe 0:437b83685196 15 void colour(void);
el12moe 0:437b83685196 16 void festive(void);
el12moe 0:437b83685196 17 void sleep(void);
el12moe 0:437b83685196 18 void presetBrightness(void);
el12moe 0:437b83685196 19 void presetColour(void);
el12moe 0:437b83685196 20 void christmas(void);
el12moe 0:437b83685196 21 void hunika(void);
el12moe 0:437b83685196 22 void akwansa(void);
el12moe 0:437b83685196 23 void rainbow(void);
el12moe 0:437b83685196 24 void rgbm(void);
el12moe 0:437b83685196 25 void christmas2(void);
el12moe 0:437b83685196 26 void hunika2(void);
el12moe 0:437b83685196 27 void akwansa2(void);
el12moe 0:437b83685196 28 void rainbow2(void);
el12moe 0:437b83685196 29 void rgbm2(void);
el12moe 0:437b83685196 30
el12moe 0:437b83685196 31 //wireless commm dependencies
el12moe 0:437b83685196 32 void xbee_detect(void);
el12moe 0:437b83685196 33 void light2(void);
el12moe 0:437b83685196 34 void light1(void);
el12moe 0:437b83685196 35 void reed1(void);
el12moe 0:437b83685196 36 void reed2(void);
el12moe 0:437b83685196 37 void count1(void);
el12moe 0:437b83685196 38 void count2(void);
el12moe 0:437b83685196 39 void count3(void);
el12moe 0:437b83685196 40 void count4(void);
el12moe 0:437b83685196 41 void normal_mode(void);
el12moe 0:437b83685196 42 void normal_mode2(void);
el12moe 0:437b83685196 43
el12moe 0:437b83685196 44 //alarm dependencies
el12moe 0:437b83685196 45 void alarmP1(void);
el12moe 0:437b83685196 46 void alarmR1(void);
el12moe 0:437b83685196 47 void alarmP2(void);
el12moe 0:437b83685196 48 void alarmR2(void);
el12moe 0:437b83685196 49
el12moe 0:437b83685196 50 void b1(void);
el12moe 0:437b83685196 51 void b2(void);
el12moe 0:437b83685196 52
el12moe 0:437b83685196 53
el12moe 0:437b83685196 54 DigitalOut myled(LED1);
el12moe 0:437b83685196 55 DigitalOut mled(LED2);
el12moe 0:437b83685196 56 DigitalOut m3led(LED3);
el12moe 0:437b83685196 57 DigitalOut m4led(LED4);
el12moe 0:437b83685196 58
el12moe 0:437b83685196 59 int xbee1 = 104;// reed switches
el12moe 0:437b83685196 60 int xbee2 = 45; // PIR
el12moe 0:437b83685196 61 int xbee3 = 76;// reed switches
el12moe 0:437b83685196 62 int xbee4 = 69;// PIR
el12moe 0:437b83685196 63
el12moe 0:437b83685196 64
el12moe 0:437b83685196 65 short counter1 = 0;
el12moe 0:437b83685196 66 short counter2 = 0;
el12moe 0:437b83685196 67 short counter3 = 0;
el12moe 0:437b83685196 68 short counter4 = 0;
el12moe 0:437b83685196 69 int readAddress = 0;
el12moe 0:437b83685196 70 int readValue=0;
el12moe 0:437b83685196 71
el12moe 0:437b83685196 72 PwmOut buzzer(p21);
el12moe 0:437b83685196 73 float frequency[]= {659,554}; //frequency array for both sound and LED (Taken from the mbed website)
el12moe 0:437b83685196 74 float beat[]= {1,1}; //beat array for both sound and LED
el12moe 0:437b83685196 75
el12moe 0:437b83685196 76 //RSP packets dependencies
el12moe 0:437b83685196 77 int room=0;
el12moe 0:437b83685196 78 int mode=0;
el12moe 0:437b83685196 79 int red=0;
el12moe 0:437b83685196 80 int green=0;
el12moe 0:437b83685196 81 int blue=0;
el12moe 0:437b83685196 82
el12moe 0:437b83685196 83 //lights mode dependencies
el12moe 0:437b83685196 84 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}};
el12moe 0:437b83685196 85 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}};
el12moe 0:437b83685196 86
el12moe 0:437b83685196 87 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}};
el12moe 0:437b83685196 88 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}};
el12moe 0:437b83685196 89
el12moe 0:437b83685196 90 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}};
el12moe 0:437b83685196 91 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}};
el12moe 0:437b83685196 92 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}};
el12moe 0:437b83685196 93 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}};
el12moe 0:437b83685196 94
el12moe 0:437b83685196 95 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}};
el12moe 0:437b83685196 96 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}};
el12moe 0:437b83685196 97 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}};
el12moe 0:437b83685196 98 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}};
el12moe 0:437b83685196 99
el12moe 0:437b83685196 100 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}};
el12moe 0:437b83685196 101 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}};
el12moe 0:437b83685196 102 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}};
el12moe 0:437b83685196 103 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}};
el12moe 0:437b83685196 104 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}};
el12moe 0:437b83685196 105 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}};
el12moe 0:437b83685196 106 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}};
el12moe 0:437b83685196 107 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}};
el12moe 0:437b83685196 108
el12moe 0:437b83685196 109
el12moe 0:437b83685196 110 int main() {
el12moe 0:437b83685196 111 xmas.attach(&mbedReceive, 1.0);
el12moe 0:437b83685196 112 while(1) {
el12moe 0:437b83685196 113 if(pi.readable()){
el12moe 0:437b83685196 114 modeActivated();
el12moe 0:437b83685196 115 //mbedReceive();
el12moe 0:437b83685196 116 }
el12moe 0:437b83685196 117 xbee_detect();
el12moe 0:437b83685196 118 normal_mode();
el12moe 0:437b83685196 119 normal_mode2();
el12moe 0:437b83685196 120 }
el12moe 0:437b83685196 121 }
el12moe 0:437b83685196 122
el12moe 0:437b83685196 123 // function to receive stuff from pi
el12moe 0:437b83685196 124 void mbedReceive(void){
el12moe 0:437b83685196 125 int section = pi.getc();
el12moe 0:437b83685196 126 if (section==1){
el12moe 0:437b83685196 127 security(); //activate security mode
el12moe 0:437b83685196 128 }
el12moe 0:437b83685196 129 else if (section==2){
el12moe 0:437b83685196 130 room = pi.getc();
el12moe 0:437b83685196 131 mode = pi.getc();
el12moe 0:437b83685196 132 red = pi.getc();
el12moe 0:437b83685196 133 green = pi.getc();
el12moe 0:437b83685196 134 blue = pi.getc();
el12moe 0:437b83685196 135 }
el12moe 0:437b83685196 136 else if (section==0){
el12moe 0:437b83685196 137 //normal lights function a way of stopping different light modes
el12moe 0:437b83685196 138 // b2() stop alarm
el12moe 0:437b83685196 139 room = pi.getc();
el12moe 0:437b83685196 140 if (room==1){
el12moe 0:437b83685196 141 //normal mode 1
el12moe 0:437b83685196 142 }
el12moe 0:437b83685196 143 else if (room==2){
el12moe 0:437b83685196 144 //normal mode 2
el12moe 0:437b83685196 145 }
el12moe 0:437b83685196 146
el12moe 0:437b83685196 147 }
el12moe 0:437b83685196 148 }
el12moe 0:437b83685196 149
el12moe 0:437b83685196 150 void modeActivated(void){
el12moe 0:437b83685196 151 mbedReceive();
el12moe 0:437b83685196 152 if (mode==1){
el12moe 0:437b83685196 153 brightness();
el12moe 0:437b83685196 154 }
el12moe 0:437b83685196 155 if (mode==2){
el12moe 0:437b83685196 156 colour();
el12moe 0:437b83685196 157 }
el12moe 0:437b83685196 158 if (mode==3){
el12moe 0:437b83685196 159 festive();
el12moe 0:437b83685196 160 }
el12moe 0:437b83685196 161 if (mode==4){
el12moe 0:437b83685196 162 sleep();
el12moe 0:437b83685196 163 }
el12moe 0:437b83685196 164 if (mode==5){
el12moe 0:437b83685196 165 presetBrightness();
el12moe 0:437b83685196 166 }
el12moe 0:437b83685196 167 if (mode==6){
el12moe 0:437b83685196 168 presetColour();
el12moe 0:437b83685196 169 }
el12moe 0:437b83685196 170
el12moe 0:437b83685196 171 }
el12moe 0:437b83685196 172
el12moe 0:437b83685196 173 void security(void){
el12moe 0:437b83685196 174
el12moe 0:437b83685196 175 }
el12moe 0:437b83685196 176
el12moe 0:437b83685196 177 void brightness(void){
el12moe 0:437b83685196 178 if (room==1){
el12moe 0:437b83685196 179 lights.setRGBStrip1(red, red, red);
el12moe 0:437b83685196 180 }
el12moe 0:437b83685196 181 if (room==2){
el12moe 0:437b83685196 182 lights.setRGBStrip2(red, red, red);
el12moe 0:437b83685196 183 }
el12moe 0:437b83685196 184 }
el12moe 0:437b83685196 185 void colour(void){
el12moe 0:437b83685196 186 if (room==1){
el12moe 0:437b83685196 187 lights.setRGBStrip1(red, green, blue);
el12moe 0:437b83685196 188 }
el12moe 0:437b83685196 189 if (room==2){
el12moe 0:437b83685196 190 lights.setRGBStrip2(red, green, blue);
el12moe 0:437b83685196 191 }
el12moe 0:437b83685196 192
el12moe 0:437b83685196 193 }
el12moe 0:437b83685196 194 void festive(void){
el12moe 0:437b83685196 195 if (room==1){
el12moe 0:437b83685196 196 if(red==1){
el12moe 0:437b83685196 197 christmas();
el12moe 0:437b83685196 198 }
el12moe 0:437b83685196 199 if(red==2){
el12moe 0:437b83685196 200 hunika();
el12moe 0:437b83685196 201 }
el12moe 0:437b83685196 202 if(red==3){
el12moe 0:437b83685196 203 akwansa();
el12moe 0:437b83685196 204 }
el12moe 0:437b83685196 205 if(red==4){
el12moe 0:437b83685196 206 rainbow();
el12moe 0:437b83685196 207 }
el12moe 0:437b83685196 208 if(red==5){
el12moe 0:437b83685196 209 rgbm();
el12moe 0:437b83685196 210 }
el12moe 0:437b83685196 211 }
el12moe 0:437b83685196 212 else if (room==2){
el12moe 0:437b83685196 213 if(red==1){
el12moe 0:437b83685196 214
el12moe 0:437b83685196 215 christmas2();
el12moe 0:437b83685196 216 }
el12moe 0:437b83685196 217 if(red==2){
el12moe 0:437b83685196 218 hunika2();
el12moe 0:437b83685196 219 }
el12moe 0:437b83685196 220 if(red==3){
el12moe 0:437b83685196 221 akwansa2();
el12moe 0:437b83685196 222 }
el12moe 0:437b83685196 223 if(red==4){
el12moe 0:437b83685196 224 rainbow2();
el12moe 0:437b83685196 225 }
el12moe 0:437b83685196 226 if(red==5){
el12moe 0:437b83685196 227 rgbm2();
el12moe 0:437b83685196 228 }
el12moe 0:437b83685196 229 }
el12moe 0:437b83685196 230 }
el12moe 0:437b83685196 231 void sleep(void){
el12moe 0:437b83685196 232 if (room==1){
el12moe 0:437b83685196 233 // setRGBStrip1(red, green, blue); sleep pattern for strip1
el12moe 0:437b83685196 234 }
el12moe 0:437b83685196 235 if (room==2){
el12moe 0:437b83685196 236 // setRGBStrip2(red, green, blue);sleep pattern for strip1
el12moe 0:437b83685196 237 }
el12moe 0:437b83685196 238 }
el12moe 0:437b83685196 239 void presetBrightness(void){
el12moe 0:437b83685196 240
el12moe 0:437b83685196 241 }
el12moe 0:437b83685196 242 void presetColour(void){
el12moe 0:437b83685196 243
el12moe 0:437b83685196 244 }
el12moe 0:437b83685196 245
el12moe 0:437b83685196 246 //xmas red & green
el12moe 0:437b83685196 247 void christmas(void){
el12moe 0:437b83685196 248 lights.setRGBPixels1(rg);
el12moe 0:437b83685196 249 wait(1);
el12moe 0:437b83685196 250 lights.setRGBPixels1(gr);
el12moe 0:437b83685196 251 wait(1);
el12moe 0:437b83685196 252 lights.setRGBPixels1(rg);
el12moe 0:437b83685196 253 wait(1);
el12moe 0:437b83685196 254 lights.setRGBPixels1(gr);
el12moe 0:437b83685196 255 wait(1);
el12moe 0:437b83685196 256 lights.setRGBPixels1(rg);
el12moe 0:437b83685196 257 wait(1);
el12moe 0:437b83685196 258 lights.setRGBPixels1(gr);
el12moe 0:437b83685196 259 wait(1);
el12moe 0:437b83685196 260 lights.setRGBPixels1(rg);
el12moe 0:437b83685196 261 wait(1);
el12moe 0:437b83685196 262 lights.setRGBPixels1(gr);
el12moe 0:437b83685196 263 wait(1);
el12moe 0:437b83685196 264 lights.setRGBPixels1(rg);
el12moe 0:437b83685196 265 wait(1);
el12moe 0:437b83685196 266 lights.setRGBPixels1(gr);
el12moe 0:437b83685196 267 wait(1);
el12moe 0:437b83685196 268 lights.setRGBStrip1(255, 0, 0);
el12moe 0:437b83685196 269 wait(1);
el12moe 0:437b83685196 270 lights.setRGBStrip1(0,255,0);
el12moe 0:437b83685196 271 wait(1);
el12moe 0:437b83685196 272 }
el12moe 0:437b83685196 273 void hunika(void){
el12moe 0:437b83685196 274 lights.setRGBPixels1(bw);
el12moe 0:437b83685196 275 wait(1);
el12moe 0:437b83685196 276 lights.setRGBPixels1(wb);
el12moe 0:437b83685196 277 wait(1);
el12moe 0:437b83685196 278 lights.setRGBPixels1(bw);
el12moe 0:437b83685196 279 wait(1);
el12moe 0:437b83685196 280 lights.setRGBPixels1(wb);
el12moe 0:437b83685196 281 wait(1);
el12moe 0:437b83685196 282 lights.setRGBPixels1(bw);
el12moe 0:437b83685196 283 wait(1);
el12moe 0:437b83685196 284 lights.setRGBPixels1(wb);
el12moe 0:437b83685196 285 wait(1);
el12moe 0:437b83685196 286 lights.setRGBPixels1(bw);
el12moe 0:437b83685196 287 wait(1);
el12moe 0:437b83685196 288 lights.setRGBPixels1(wb);
el12moe 0:437b83685196 289 wait(1);
el12moe 0:437b83685196 290 lights.setRGBPixels1(bw);
el12moe 0:437b83685196 291 wait(1);
el12moe 0:437b83685196 292 lights.setRGBPixels1(wb);
el12moe 0:437b83685196 293 wait(1);
el12moe 0:437b83685196 294 lights.setRGBStrip1(0, 0, 255);
el12moe 0:437b83685196 295 wait(1);
el12moe 0:437b83685196 296 lights.setRGBStrip1(255,255,255);
el12moe 0:437b83685196 297 wait(1);
el12moe 0:437b83685196 298 }
el12moe 0:437b83685196 299
el12moe 0:437b83685196 300 void akwansa(void){
el12moe 0:437b83685196 301 lights.setRGBPixels1(ak1);
el12moe 0:437b83685196 302 wait(1);
el12moe 0:437b83685196 303 lights.setRGBPixels1(ak2);
el12moe 0:437b83685196 304 wait(1);
el12moe 0:437b83685196 305 lights.setRGBPixels1(ak3);
el12moe 0:437b83685196 306 wait(1);
el12moe 0:437b83685196 307 lights.setRGBPixels1(ak4);
el12moe 0:437b83685196 308 wait(1);
el12moe 0:437b83685196 309 lights.setRGBPixels1(ak1);
el12moe 0:437b83685196 310 wait(1);
el12moe 0:437b83685196 311 lights.setRGBPixels1(ak2);
el12moe 0:437b83685196 312 wait(1);
el12moe 0:437b83685196 313 lights.setRGBPixels1(ak3);
el12moe 0:437b83685196 314 wait(1);
el12moe 0:437b83685196 315 lights.setRGBPixels1(ak4);
el12moe 0:437b83685196 316 wait(1);
el12moe 0:437b83685196 317 lights.setRGBPixels1(ak1);
el12moe 0:437b83685196 318 wait(1);
el12moe 0:437b83685196 319 lights.setRGBPixels1(ak2);
el12moe 0:437b83685196 320 wait(1);
el12moe 0:437b83685196 321 lights.setRGBPixels1(ak3);
el12moe 0:437b83685196 322 wait(1);
el12moe 0:437b83685196 323 lights.setRGBPixels1(ak4);
el12moe 0:437b83685196 324 wait(1);
el12moe 0:437b83685196 325 }
el12moe 0:437b83685196 326 void rainbow(void){
el12moe 0:437b83685196 327 lights.setRGBPixels1(ra1);
el12moe 0:437b83685196 328 wait(1);
el12moe 0:437b83685196 329 lights.setRGBPixels1(ra2);
el12moe 0:437b83685196 330 wait(1);
el12moe 0:437b83685196 331 lights.setRGBPixels1(ra3);
el12moe 0:437b83685196 332 wait(1);
el12moe 0:437b83685196 333 lights.setRGBPixels1(ra4);
el12moe 0:437b83685196 334 wait(1);
el12moe 0:437b83685196 335 lights.setRGBPixels1(ra5);
el12moe 0:437b83685196 336 wait(1);
el12moe 0:437b83685196 337 lights.setRGBPixels1(ra6);
el12moe 0:437b83685196 338 wait(1);
el12moe 0:437b83685196 339 lights.setRGBPixels1(ra7);
el12moe 0:437b83685196 340 wait(1);
el12moe 0:437b83685196 341 lights.setRGBPixels1(ra8);
el12moe 0:437b83685196 342 wait(1);
el12moe 0:437b83685196 343 }
el12moe 0:437b83685196 344
el12moe 0:437b83685196 345 void rgbm(void){
el12moe 0:437b83685196 346 lights.setRGBPixels2(rgb);
el12moe 0:437b83685196 347 wait(1);
el12moe 0:437b83685196 348 lights.setRGBPixels2(brg);
el12moe 0:437b83685196 349 wait(1);
el12moe 0:437b83685196 350 lights.setRGBPixels2(gbr);
el12moe 0:437b83685196 351 wait(1);
el12moe 0:437b83685196 352 lights.setRGBPixels2(bgr);
el12moe 0:437b83685196 353 wait(1);
el12moe 0:437b83685196 354 lights.setRGBPixels2(rgb);
el12moe 0:437b83685196 355 wait(1);
el12moe 0:437b83685196 356 lights.setRGBPixels2(brg);
el12moe 0:437b83685196 357 wait(1);
el12moe 0:437b83685196 358 lights.setRGBPixels2(gbr);
el12moe 0:437b83685196 359 wait(1);
el12moe 0:437b83685196 360 lights.setRGBPixels2(bgr);
el12moe 0:437b83685196 361 wait(1);
el12moe 0:437b83685196 362 lights.setRGBPixels2(rgb);
el12moe 0:437b83685196 363 wait(1);
el12moe 0:437b83685196 364 lights.setRGBPixels2(brg);
el12moe 0:437b83685196 365 wait(1);
el12moe 0:437b83685196 366 lights.setRGBPixels2(gbr);
el12moe 0:437b83685196 367 wait(1);
el12moe 0:437b83685196 368 lights.setRGBPixels2(bgr);
el12moe 0:437b83685196 369 wait(1);
el12moe 0:437b83685196 370 lights.setRGBStrip2(255, 0, 0);
el12moe 0:437b83685196 371 wait(1);
el12moe 0:437b83685196 372 lights.setRGBStrip2(0,255,0);
el12moe 0:437b83685196 373 wait(1);
el12moe 0:437b83685196 374 lights.setRGBStrip2(0,0,255);
el12moe 0:437b83685196 375 wait(1);
el12moe 0:437b83685196 376 }
el12moe 0:437b83685196 377
el12moe 0:437b83685196 378 void christmas2(void){
el12moe 0:437b83685196 379 lights.setRGBPixels2(rg);
el12moe 0:437b83685196 380 wait(1);
el12moe 0:437b83685196 381 lights.setRGBPixels2(gr);
el12moe 0:437b83685196 382 wait(1);
el12moe 0:437b83685196 383 lights.setRGBPixels2(rg);
el12moe 0:437b83685196 384 wait(1);
el12moe 0:437b83685196 385 lights.setRGBPixels2(gr);
el12moe 0:437b83685196 386 wait(1);
el12moe 0:437b83685196 387 lights.setRGBPixels2(rg);
el12moe 0:437b83685196 388 wait(1);
el12moe 0:437b83685196 389 lights.setRGBPixels2(gr);
el12moe 0:437b83685196 390 wait(1);
el12moe 0:437b83685196 391 lights.setRGBPixels2(rg);
el12moe 0:437b83685196 392 wait(1);
el12moe 0:437b83685196 393 lights.setRGBPixels2(gr);
el12moe 0:437b83685196 394 wait(1);
el12moe 0:437b83685196 395 lights.setRGBPixels2(rg);
el12moe 0:437b83685196 396 wait(1);
el12moe 0:437b83685196 397 lights.setRGBPixels2(gr);
el12moe 0:437b83685196 398 wait(1);
el12moe 0:437b83685196 399 lights.setRGBStrip2(255, 0, 0);
el12moe 0:437b83685196 400 wait(1);
el12moe 0:437b83685196 401 lights.setRGBStrip2(0,255,0);
el12moe 0:437b83685196 402 wait(1);
el12moe 0:437b83685196 403 }
el12moe 0:437b83685196 404
el12moe 0:437b83685196 405 void hunika2(void){
el12moe 0:437b83685196 406 lights.setRGBPixels2(bw);
el12moe 0:437b83685196 407 wait(1);
el12moe 0:437b83685196 408 lights.setRGBPixels2(wb);
el12moe 0:437b83685196 409 wait(1);
el12moe 0:437b83685196 410 lights.setRGBPixels2(bw);
el12moe 0:437b83685196 411 wait(1);
el12moe 0:437b83685196 412 lights.setRGBPixels2(wb);
el12moe 0:437b83685196 413 wait(1);
el12moe 0:437b83685196 414 lights.setRGBPixels2(bw);
el12moe 0:437b83685196 415 wait(1);
el12moe 0:437b83685196 416 lights.setRGBPixels2(wb);
el12moe 0:437b83685196 417 wait(1);
el12moe 0:437b83685196 418 lights.setRGBPixels2(bw);
el12moe 0:437b83685196 419 wait(1);
el12moe 0:437b83685196 420 lights.setRGBPixels2(wb);
el12moe 0:437b83685196 421 wait(1);
el12moe 0:437b83685196 422 lights.setRGBPixels2(bw);
el12moe 0:437b83685196 423 wait(1);
el12moe 0:437b83685196 424 lights.setRGBPixels2(wb);
el12moe 0:437b83685196 425 wait(1);
el12moe 0:437b83685196 426 lights.setRGBStrip2(0, 0, 255);
el12moe 0:437b83685196 427 wait(1);
el12moe 0:437b83685196 428 lights.setRGBStrip2(255,255,255);
el12moe 0:437b83685196 429 wait(1);
el12moe 0:437b83685196 430 }
el12moe 0:437b83685196 431
el12moe 0:437b83685196 432 void akwansa2(void){
el12moe 0:437b83685196 433 lights.setRGBPixels2(ak1);
el12moe 0:437b83685196 434 wait(1);
el12moe 0:437b83685196 435 lights.setRGBPixels2(ak2);
el12moe 0:437b83685196 436 wait(1);
el12moe 0:437b83685196 437 lights.setRGBPixels2(ak3);
el12moe 0:437b83685196 438 wait(1);
el12moe 0:437b83685196 439 lights.setRGBPixels2(ak4);
el12moe 0:437b83685196 440 wait(1);
el12moe 0:437b83685196 441 lights.setRGBPixels2(ak1);
el12moe 0:437b83685196 442 wait(1);
el12moe 0:437b83685196 443 lights.setRGBPixels2(ak2);
el12moe 0:437b83685196 444 wait(1);
el12moe 0:437b83685196 445 lights.setRGBPixels2(ak3);
el12moe 0:437b83685196 446 wait(1);
el12moe 0:437b83685196 447 lights.setRGBPixels2(ak4);
el12moe 0:437b83685196 448 wait(1);
el12moe 0:437b83685196 449 lights.setRGBPixels2(ak1);
el12moe 0:437b83685196 450 wait(1);
el12moe 0:437b83685196 451 lights.setRGBPixels2(ak2);
el12moe 0:437b83685196 452 wait(1);
el12moe 0:437b83685196 453 lights.setRGBPixels2(ak3);
el12moe 0:437b83685196 454 wait(1);
el12moe 0:437b83685196 455 lights.setRGBPixels2(ak4);
el12moe 0:437b83685196 456 wait(1);
el12moe 0:437b83685196 457 }
el12moe 0:437b83685196 458
el12moe 0:437b83685196 459
el12moe 0:437b83685196 460 void rainbow2(void){
el12moe 0:437b83685196 461 lights.setRGBPixels2(ra1);
el12moe 0:437b83685196 462 wait(1);
el12moe 0:437b83685196 463 lights.setRGBPixels2(ra2);
el12moe 0:437b83685196 464 wait(1);
el12moe 0:437b83685196 465 lights.setRGBPixels2(ra3);
el12moe 0:437b83685196 466 wait(1);
el12moe 0:437b83685196 467 lights.setRGBPixels2(ra4);
el12moe 0:437b83685196 468 wait(1);
el12moe 0:437b83685196 469 lights.setRGBPixels2(ra5);
el12moe 0:437b83685196 470 wait(1);
el12moe 0:437b83685196 471 lights.setRGBPixels2(ra6);
el12moe 0:437b83685196 472 wait(1);
el12moe 0:437b83685196 473 lights.setRGBPixels2(ra7);
el12moe 0:437b83685196 474 wait(1);
el12moe 0:437b83685196 475 lights.setRGBPixels2(ra8);
el12moe 0:437b83685196 476 wait(1);
el12moe 0:437b83685196 477 }
el12moe 0:437b83685196 478
el12moe 0:437b83685196 479
el12moe 0:437b83685196 480 void rgbm2(void){
el12moe 0:437b83685196 481 lights.setRGBPixels2(rgb);
el12moe 0:437b83685196 482 wait(1);
el12moe 0:437b83685196 483 lights.setRGBPixels2(brg);
el12moe 0:437b83685196 484 wait(1);
el12moe 0:437b83685196 485 lights.setRGBPixels2(gbr);
el12moe 0:437b83685196 486 wait(1);
el12moe 0:437b83685196 487 lights.setRGBPixels2(bgr);
el12moe 0:437b83685196 488 wait(1);
el12moe 0:437b83685196 489 lights.setRGBPixels2(rgb);
el12moe 0:437b83685196 490 wait(1);
el12moe 0:437b83685196 491 lights.setRGBPixels2(brg);
el12moe 0:437b83685196 492 wait(1);
el12moe 0:437b83685196 493 lights.setRGBPixels2(gbr);
el12moe 0:437b83685196 494 wait(1);
el12moe 0:437b83685196 495 lights.setRGBPixels2(bgr);
el12moe 0:437b83685196 496 wait(1);
el12moe 0:437b83685196 497 lights.setRGBPixels2(rgb);
el12moe 0:437b83685196 498 wait(1);
el12moe 0:437b83685196 499 lights.setRGBPixels2(brg);
el12moe 0:437b83685196 500 wait(1);
el12moe 0:437b83685196 501 lights.setRGBPixels2(gbr);
el12moe 0:437b83685196 502 wait(1);
el12moe 0:437b83685196 503 lights.setRGBPixels2(bgr);
el12moe 0:437b83685196 504 wait(1);
el12moe 0:437b83685196 505 lights.setRGBStrip2(255, 0, 0);
el12moe 0:437b83685196 506 wait(1);
el12moe 0:437b83685196 507 lights.setRGBStrip2(0,255,0);
el12moe 0:437b83685196 508 wait(1);
el12moe 0:437b83685196 509 lights.setRGBStrip2(0,0,255);
el12moe 0:437b83685196 510 wait(1);
el12moe 0:437b83685196 511 }
el12moe 0:437b83685196 512
el12moe 0:437b83685196 513 void xbee_detect(void){
el12moe 0:437b83685196 514 if (xbee.getc() == 0x7E) {
el12moe 0:437b83685196 515 for (int i = 0; i < 19; i++) {
el12moe 0:437b83685196 516 if (i<10){
el12moe 0:437b83685196 517 int discard = xbee.getc();
el12moe 0:437b83685196 518 }
el12moe 0:437b83685196 519 else if (i<11){
el12moe 0:437b83685196 520 readAddress = xbee.getc();
el12moe 0:437b83685196 521 }
el12moe 0:437b83685196 522 else{
el12moe 0:437b83685196 523 int discarded = xbee.getc();
el12moe 0:437b83685196 524 }
el12moe 0:437b83685196 525 }
el12moe 0:437b83685196 526 readValue = xbee.getc();
el12moe 0:437b83685196 527 }
el12moe 0:437b83685196 528 }
el12moe 0:437b83685196 529 //lights room1
el12moe 0:437b83685196 530 void light1(void){
el12moe 0:437b83685196 531 if ( readAddress == xbee2){
el12moe 0:437b83685196 532 if (readValue == 0){
el12moe 0:437b83685196 533 counter2++;
el12moe 0:437b83685196 534 count2();
el12moe 0:437b83685196 535 }
el12moe 0:437b83685196 536 else if(readValue == 16){
el12moe 0:437b83685196 537 counter2 = 0;
el12moe 0:437b83685196 538 lights.setRGBStrip1(127,127,127);
el12moe 0:437b83685196 539 // wait(2);//mled = 1;
el12moe 0:437b83685196 540 }
el12moe 0:437b83685196 541 }
el12moe 0:437b83685196 542 }
el12moe 0:437b83685196 543 //room 2
el12moe 0:437b83685196 544 void light2(void){
el12moe 0:437b83685196 545 if ( readAddress == xbee4){
el12moe 0:437b83685196 546 if (readValue == 0){
el12moe 0:437b83685196 547 counter4++;
el12moe 0:437b83685196 548 count4();
el12moe 0:437b83685196 549
el12moe 0:437b83685196 550 }
el12moe 0:437b83685196 551
el12moe 0:437b83685196 552 else if(readValue == 16){
el12moe 0:437b83685196 553 counter4 = 0;
el12moe 0:437b83685196 554 lights.setRGBStrip2(127,127,127);
el12moe 0:437b83685196 555 }
el12moe 0:437b83685196 556 }
el12moe 0:437b83685196 557 }
el12moe 0:437b83685196 558
el12moe 0:437b83685196 559 void reed1(void){
el12moe 0:437b83685196 560 if( readAddress == xbee1){
el12moe 0:437b83685196 561 if (readValue == 0){
el12moe 0:437b83685196 562 //counter1++;
el12moe 0:437b83685196 563 // count1();
el12moe 0:437b83685196 564 b2();
el12moe 0:437b83685196 565 }
el12moe 0:437b83685196 566 else if(readValue == 16){
el12moe 0:437b83685196 567 counter1 = 0;
el12moe 0:437b83685196 568 // myled = 1;
el12moe 0:437b83685196 569 b1();
el12moe 0:437b83685196 570 }
el12moe 0:437b83685196 571 }
el12moe 0:437b83685196 572 }
el12moe 0:437b83685196 573 //room 2
el12moe 0:437b83685196 574 void reed2(void){
el12moe 0:437b83685196 575 if ( readAddress == xbee3){
el12moe 0:437b83685196 576 if (readValue == 0){
el12moe 0:437b83685196 577 //counter3++;
el12moe 0:437b83685196 578 //count3();
el12moe 0:437b83685196 579 b2();
el12moe 0:437b83685196 580 }
el12moe 0:437b83685196 581 else if(readValue == 16){
el12moe 0:437b83685196 582 //counter3 = 0;
el12moe 0:437b83685196 583 // m3led = 1;
el12moe 0:437b83685196 584 b1();
el12moe 0:437b83685196 585 }
el12moe 0:437b83685196 586 }
el12moe 0:437b83685196 587 }
el12moe 0:437b83685196 588
el12moe 0:437b83685196 589 void count1(void){
el12moe 0:437b83685196 590 if(counter1==10){
el12moe 0:437b83685196 591 myled = 0;
el12moe 0:437b83685196 592 counter1 = 0;
el12moe 0:437b83685196 593 }
el12moe 0:437b83685196 594 }
el12moe 0:437b83685196 595 void count3(void){
el12moe 0:437b83685196 596 if(counter3==10){
el12moe 0:437b83685196 597 m3led = 0;
el12moe 0:437b83685196 598 counter1 = 0;
el12moe 0:437b83685196 599 }
el12moe 0:437b83685196 600 }
el12moe 0:437b83685196 601
el12moe 0:437b83685196 602 //lights count
el12moe 0:437b83685196 603 void count2(void){
el12moe 0:437b83685196 604 if(counter2==150){
el12moe 0:437b83685196 605 lights.setRGBStrip1(0,0,0);
el12moe 0:437b83685196 606 counter2 = 0;
el12moe 0:437b83685196 607 }
el12moe 0:437b83685196 608 }
el12moe 0:437b83685196 609
el12moe 0:437b83685196 610 void count4(void){
el12moe 0:437b83685196 611 if(counter4==150){
el12moe 0:437b83685196 612 lights.setRGBStrip2(0,0,0);
el12moe 0:437b83685196 613 counter2 = 0;
el12moe 0:437b83685196 614 }
el12moe 0:437b83685196 615 }
el12moe 0:437b83685196 616
el12moe 0:437b83685196 617 void b1(void){
el12moe 0:437b83685196 618 for (int i=0; i<=1; i++) {
el12moe 0:437b83685196 619 buzzer.period(1/(frequency[i])); // set PWM period
el12moe 0:437b83685196 620 buzzer=0; // set duty cycle
el12moe 0:437b83685196 621 //wait(0.1*beat[i]); // hold for beat period
el12moe 0:437b83685196 622 // myled = 1;
el12moe 0:437b83685196 623
el12moe 0:437b83685196 624 }
el12moe 0:437b83685196 625 }
el12moe 0:437b83685196 626
el12moe 0:437b83685196 627 void b2(void){
el12moe 0:437b83685196 628 for (int i=0; i<=1; i++) {
el12moe 0:437b83685196 629 buzzer.period(1/(frequency[i])); // set PWM period
el12moe 0:437b83685196 630 buzzer=0.9; // set duty cycle
el12moe 0:437b83685196 631 //wait(0.1*beat[i]); // hold for beat period
el12moe 0:437b83685196 632 // myled = 1;
el12moe 0:437b83685196 633
el12moe 0:437b83685196 634 }
el12moe 0:437b83685196 635 }
el12moe 0:437b83685196 636
el12moe 0:437b83685196 637 void normal_mode(void){
el12moe 0:437b83685196 638 // light2();
el12moe 0:437b83685196 639 light1();
el12moe 0:437b83685196 640 reed1();
el12moe 0:437b83685196 641 //reed2();
el12moe 0:437b83685196 642 }
el12moe 0:437b83685196 643
el12moe 0:437b83685196 644 void normal_mode2(void){
el12moe 0:437b83685196 645 light2();
el12moe 0:437b83685196 646 //light1();
el12moe 0:437b83685196 647 //reed1();
el12moe 0:437b83685196 648 reed2();
el12moe 0:437b83685196 649 }
el12moe 0:437b83685196 650
el12moe 0:437b83685196 651
el12moe 0:437b83685196 652 // Alarm Dependencies
el12moe 0:437b83685196 653 void alarmP1(void){
el12moe 0:437b83685196 654 if ( readAddress == xbee2){
el12moe 0:437b83685196 655 if (readValue == 0){
el12moe 0:437b83685196 656 counter2++;
el12moe 0:437b83685196 657 count2();
el12moe 0:437b83685196 658 }
el12moe 0:437b83685196 659 else if(readValue == 16){
el12moe 0:437b83685196 660 counter2 = 0;
el12moe 0:437b83685196 661 lights.setRGBStrip1(127,127,127);
el12moe 0:437b83685196 662 b2();
el12moe 0:437b83685196 663 // wait(2);//mled = 1;
el12moe 0:437b83685196 664 }
el12moe 0:437b83685196 665 }
el12moe 0:437b83685196 666 }
el12moe 0:437b83685196 667 //room 2
el12moe 0:437b83685196 668 void alarmP2(void){
el12moe 0:437b83685196 669 if ( readAddress == xbee4){
el12moe 0:437b83685196 670 if (readValue == 0){
el12moe 0:437b83685196 671 counter4++;
el12moe 0:437b83685196 672 count4();
el12moe 0:437b83685196 673 }
el12moe 0:437b83685196 674
el12moe 0:437b83685196 675 else if(readValue == 16){
el12moe 0:437b83685196 676 counter4 = 0;
el12moe 0:437b83685196 677 lights.setRGBStrip2(127,127,127);
el12moe 0:437b83685196 678 b2();
el12moe 0:437b83685196 679 }
el12moe 0:437b83685196 680 }
el12moe 0:437b83685196 681 }
el12moe 0:437b83685196 682
el12moe 0:437b83685196 683 void alarmR1(void){
el12moe 0:437b83685196 684 if( readAddress == xbee1){
el12moe 0:437b83685196 685 if (readValue == 0){
el12moe 0:437b83685196 686 //counter1++;
el12moe 0:437b83685196 687 // count1();
el12moe 0:437b83685196 688 b2();
el12moe 0:437b83685196 689 }
el12moe 0:437b83685196 690 else if(readValue == 16){
el12moe 0:437b83685196 691 counter1 = 0;
el12moe 0:437b83685196 692 // myled = 1;
el12moe 0:437b83685196 693 //b1();
el12moe 0:437b83685196 694 }
el12moe 0:437b83685196 695 }
el12moe 0:437b83685196 696 }
el12moe 0:437b83685196 697 //room 2
el12moe 0:437b83685196 698 void alarmR2(void){
el12moe 0:437b83685196 699 if ( readAddress == xbee3){
el12moe 0:437b83685196 700 if (readValue == 0){
el12moe 0:437b83685196 701 //counter3++;
el12moe 0:437b83685196 702 //count3();
el12moe 0:437b83685196 703 b2();
el12moe 0:437b83685196 704 }
el12moe 0:437b83685196 705 else if(readValue == 16){
el12moe 0:437b83685196 706 //counter3 = 0;
el12moe 0:437b83685196 707 // m3led = 1;
el12moe 0:437b83685196 708 // b1();
el12moe 0:437b83685196 709 }
el12moe 0:437b83685196 710 }
el12moe 0:437b83685196 711 }