rsp to mbed
Dependencies: mbed neopixels_spi
Fork of RSP_receivefunction by
main.cpp@0:3f93f42809e5, 2015-05-02 (annotated)
- Committer:
- el12moe
- Date:
- Sat May 02 15:50:20 2015 +0000
- Revision:
- 0:3f93f42809e5
- Child:
- 1:bcb384b83f54
RSP to mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el12moe | 0:3f93f42809e5 | 1 | #include "mbed.h" |
el12moe | 0:3f93f42809e5 | 2 | |
el12moe | 0:3f93f42809e5 | 3 | Serial pi(USBTX, USBRX);// Initialse USB serial port |
el12moe | 0:3f93f42809e5 | 4 | void mbedReceive(void); |
el12moe | 0:3f93f42809e5 | 5 | void modeActivated(void); |
el12moe | 0:3f93f42809e5 | 6 | void security(void); |
el12moe | 0:3f93f42809e5 | 7 | void brightness(void); |
el12moe | 0:3f93f42809e5 | 8 | void colour(void); |
el12moe | 0:3f93f42809e5 | 9 | void festive(void); |
el12moe | 0:3f93f42809e5 | 10 | void sleep(void); |
el12moe | 0:3f93f42809e5 | 11 | void presetBrightness(void); |
el12moe | 0:3f93f42809e5 | 12 | void presetColour(void); |
el12moe | 0:3f93f42809e5 | 13 | void christmas(void); |
el12moe | 0:3f93f42809e5 | 14 | void hunika(void); |
el12moe | 0:3f93f42809e5 | 15 | void akwansa(void); |
el12moe | 0:3f93f42809e5 | 16 | void rainbow(void); |
el12moe | 0:3f93f42809e5 | 17 | void rgb(void); |
el12moe | 0:3f93f42809e5 | 18 | void christmas2(void); |
el12moe | 0:3f93f42809e5 | 19 | void hunika2(void); |
el12moe | 0:3f93f42809e5 | 20 | void akwansa2(void); |
el12moe | 0:3f93f42809e5 | 21 | void rainbow2(void); |
el12moe | 0:3f93f42809e5 | 22 | void rgb2(void); |
el12moe | 0:3f93f42809e5 | 23 | |
el12moe | 0:3f93f42809e5 | 24 | int room=0; |
el12moe | 0:3f93f42809e5 | 25 | int mode=0; |
el12moe | 0:3f93f42809e5 | 26 | int red=0; |
el12moe | 0:3f93f42809e5 | 27 | int green=0; |
el12moe | 0:3f93f42809e5 | 28 | int blue=0; |
el12moe | 0:3f93f42809e5 | 29 | |
el12moe | 0:3f93f42809e5 | 30 | |
el12moe | 0:3f93f42809e5 | 31 | int main() { |
el12moe | 0:3f93f42809e5 | 32 | while(1) { |
el12moe | 0:3f93f42809e5 | 33 | if(pi.readable()){ |
el12moe | 0:3f93f42809e5 | 34 | modeActivated(); |
el12moe | 0:3f93f42809e5 | 35 | //mbedReceive(); |
el12moe | 0:3f93f42809e5 | 36 | } |
el12moe | 0:3f93f42809e5 | 37 | } |
el12moe | 0:3f93f42809e5 | 38 | } |
el12moe | 0:3f93f42809e5 | 39 | |
el12moe | 0:3f93f42809e5 | 40 | // function to receive stuff from pi |
el12moe | 0:3f93f42809e5 | 41 | void mbedReceive(void){ |
el12moe | 0:3f93f42809e5 | 42 | int section = pi.getc(); |
el12moe | 0:3f93f42809e5 | 43 | if (section==1){ |
el12moe | 0:3f93f42809e5 | 44 | security(); //activate security mode |
el12moe | 0:3f93f42809e5 | 45 | } |
el12moe | 0:3f93f42809e5 | 46 | else if (section==2){ |
el12moe | 0:3f93f42809e5 | 47 | room = pi.getc(); |
el12moe | 0:3f93f42809e5 | 48 | mode = pi.getc(); |
el12moe | 0:3f93f42809e5 | 49 | red = pi.getc(); |
el12moe | 0:3f93f42809e5 | 50 | green = pi.getc(); |
el12moe | 0:3f93f42809e5 | 51 | blue = pi.getc(); |
el12moe | 0:3f93f42809e5 | 52 | } |
el12moe | 0:3f93f42809e5 | 53 | else if (section==0){ |
el12moe | 0:3f93f42809e5 | 54 | //normal lights function a way of stopping different light modes |
el12moe | 0:3f93f42809e5 | 55 | } |
el12moe | 0:3f93f42809e5 | 56 | } |
el12moe | 0:3f93f42809e5 | 57 | |
el12moe | 0:3f93f42809e5 | 58 | void modeActivated(void){ |
el12moe | 0:3f93f42809e5 | 59 | mbedReceive(); |
el12moe | 0:3f93f42809e5 | 60 | if (mode==1){ |
el12moe | 0:3f93f42809e5 | 61 | brightness(); |
el12moe | 0:3f93f42809e5 | 62 | } |
el12moe | 0:3f93f42809e5 | 63 | if (mode==2){ |
el12moe | 0:3f93f42809e5 | 64 | colour(); |
el12moe | 0:3f93f42809e5 | 65 | } |
el12moe | 0:3f93f42809e5 | 66 | if (mode==3){ |
el12moe | 0:3f93f42809e5 | 67 | festive(); |
el12moe | 0:3f93f42809e5 | 68 | } |
el12moe | 0:3f93f42809e5 | 69 | if (mode==4){ |
el12moe | 0:3f93f42809e5 | 70 | sleep(); |
el12moe | 0:3f93f42809e5 | 71 | } |
el12moe | 0:3f93f42809e5 | 72 | if (mode==5){ |
el12moe | 0:3f93f42809e5 | 73 | presetBrightness(); |
el12moe | 0:3f93f42809e5 | 74 | } |
el12moe | 0:3f93f42809e5 | 75 | if (mode==6){ |
el12moe | 0:3f93f42809e5 | 76 | presetColour(); |
el12moe | 0:3f93f42809e5 | 77 | } |
el12moe | 0:3f93f42809e5 | 78 | |
el12moe | 0:3f93f42809e5 | 79 | } |
el12moe | 0:3f93f42809e5 | 80 | |
el12moe | 0:3f93f42809e5 | 81 | void security(void){ |
el12moe | 0:3f93f42809e5 | 82 | |
el12moe | 0:3f93f42809e5 | 83 | } |
el12moe | 0:3f93f42809e5 | 84 | |
el12moe | 0:3f93f42809e5 | 85 | void brightness(void){ |
el12moe | 0:3f93f42809e5 | 86 | if (room==1){ |
el12moe | 0:3f93f42809e5 | 87 | // setRGBStrip1(red, green, blue); |
el12moe | 0:3f93f42809e5 | 88 | } |
el12moe | 0:3f93f42809e5 | 89 | if (room==2){ |
el12moe | 0:3f93f42809e5 | 90 | // setRGBStrip2(red, green, blue); |
el12moe | 0:3f93f42809e5 | 91 | } |
el12moe | 0:3f93f42809e5 | 92 | } |
el12moe | 0:3f93f42809e5 | 93 | void colour(void){ |
el12moe | 0:3f93f42809e5 | 94 | if (room==1){ |
el12moe | 0:3f93f42809e5 | 95 | // setRGBStrip1(red, green, blue); |
el12moe | 0:3f93f42809e5 | 96 | } |
el12moe | 0:3f93f42809e5 | 97 | if (room==2){ |
el12moe | 0:3f93f42809e5 | 98 | // setRGBStrip2(red, green, blue); |
el12moe | 0:3f93f42809e5 | 99 | } |
el12moe | 0:3f93f42809e5 | 100 | |
el12moe | 0:3f93f42809e5 | 101 | } |
el12moe | 0:3f93f42809e5 | 102 | void festive(void){ |
el12moe | 0:3f93f42809e5 | 103 | if (room==1){ |
el12moe | 0:3f93f42809e5 | 104 | if(red==1){ |
el12moe | 0:3f93f42809e5 | 105 | christmas(); |
el12moe | 0:3f93f42809e5 | 106 | } |
el12moe | 0:3f93f42809e5 | 107 | if(red==2){ |
el12moe | 0:3f93f42809e5 | 108 | hunika(); |
el12moe | 0:3f93f42809e5 | 109 | } |
el12moe | 0:3f93f42809e5 | 110 | if(red==3){ |
el12moe | 0:3f93f42809e5 | 111 | akwansa(); |
el12moe | 0:3f93f42809e5 | 112 | } |
el12moe | 0:3f93f42809e5 | 113 | if(red==4){ |
el12moe | 0:3f93f42809e5 | 114 | rainbow(); |
el12moe | 0:3f93f42809e5 | 115 | } |
el12moe | 0:3f93f42809e5 | 116 | if(red==5){ |
el12moe | 0:3f93f42809e5 | 117 | rgb(); |
el12moe | 0:3f93f42809e5 | 118 | } |
el12moe | 0:3f93f42809e5 | 119 | } |
el12moe | 0:3f93f42809e5 | 120 | else if (room==2){ |
el12moe | 0:3f93f42809e5 | 121 | if(red==1){ |
el12moe | 0:3f93f42809e5 | 122 | christmas2(); |
el12moe | 0:3f93f42809e5 | 123 | } |
el12moe | 0:3f93f42809e5 | 124 | if(red==2){ |
el12moe | 0:3f93f42809e5 | 125 | hunika2(); |
el12moe | 0:3f93f42809e5 | 126 | } |
el12moe | 0:3f93f42809e5 | 127 | if(red==3){ |
el12moe | 0:3f93f42809e5 | 128 | akwansa2(); |
el12moe | 0:3f93f42809e5 | 129 | } |
el12moe | 0:3f93f42809e5 | 130 | if(red==4){ |
el12moe | 0:3f93f42809e5 | 131 | rainbow2(); |
el12moe | 0:3f93f42809e5 | 132 | } |
el12moe | 0:3f93f42809e5 | 133 | if(red==5){ |
el12moe | 0:3f93f42809e5 | 134 | rgb2(); |
el12moe | 0:3f93f42809e5 | 135 | } |
el12moe | 0:3f93f42809e5 | 136 | } |
el12moe | 0:3f93f42809e5 | 137 | } |
el12moe | 0:3f93f42809e5 | 138 | void sleep(void){ |
el12moe | 0:3f93f42809e5 | 139 | if (room==1){ |
el12moe | 0:3f93f42809e5 | 140 | // setRGBStrip1(red, green, blue); sleep pattern for strip1 |
el12moe | 0:3f93f42809e5 | 141 | } |
el12moe | 0:3f93f42809e5 | 142 | if (room==2){ |
el12moe | 0:3f93f42809e5 | 143 | // setRGBStrip2(red, green, blue);sleep pattern for strip1 |
el12moe | 0:3f93f42809e5 | 144 | } |
el12moe | 0:3f93f42809e5 | 145 | } |
el12moe | 0:3f93f42809e5 | 146 | void presetBrightness(void){ |
el12moe | 0:3f93f42809e5 | 147 | |
el12moe | 0:3f93f42809e5 | 148 | } |
el12moe | 0:3f93f42809e5 | 149 | void presetColour(void){ |
el12moe | 0:3f93f42809e5 | 150 | |
el12moe | 0:3f93f42809e5 | 151 | } |
el12moe | 0:3f93f42809e5 | 152 | |
el12moe | 0:3f93f42809e5 | 153 | void christmas(void){ |
el12moe | 0:3f93f42809e5 | 154 | |
el12moe | 0:3f93f42809e5 | 155 | } |
el12moe | 0:3f93f42809e5 | 156 | void hunika(void){ |
el12moe | 0:3f93f42809e5 | 157 | |
el12moe | 0:3f93f42809e5 | 158 | } |
el12moe | 0:3f93f42809e5 | 159 | void akwansa(void){ |
el12moe | 0:3f93f42809e5 | 160 | |
el12moe | 0:3f93f42809e5 | 161 | } |
el12moe | 0:3f93f42809e5 | 162 | void rainbow(void){ |
el12moe | 0:3f93f42809e5 | 163 | |
el12moe | 0:3f93f42809e5 | 164 | } |
el12moe | 0:3f93f42809e5 | 165 | void rgb(void){ |
el12moe | 0:3f93f42809e5 | 166 | |
el12moe | 0:3f93f42809e5 | 167 | } |
el12moe | 0:3f93f42809e5 | 168 | void christmas2(void){ |
el12moe | 0:3f93f42809e5 | 169 | |
el12moe | 0:3f93f42809e5 | 170 | } |
el12moe | 0:3f93f42809e5 | 171 | void hunika2(void){ |
el12moe | 0:3f93f42809e5 | 172 | |
el12moe | 0:3f93f42809e5 | 173 | } |
el12moe | 0:3f93f42809e5 | 174 | void akwansa2(void){ |
el12moe | 0:3f93f42809e5 | 175 | |
el12moe | 0:3f93f42809e5 | 176 | } |
el12moe | 0:3f93f42809e5 | 177 | void rainbow2(void){ |
el12moe | 0:3f93f42809e5 | 178 | |
el12moe | 0:3f93f42809e5 | 179 | } |
el12moe | 0:3f93f42809e5 | 180 | void rgb2(void){ |
el12moe | 0:3f93f42809e5 | 181 | |
el12moe | 0:3f93f42809e5 | 182 | } |