123
Dependencies: WS2812 PixelArray DebounceIn
main.h@1:af17c65e86dc, 2020-07-02 (annotated)
- Committer:
- turumputum
- Date:
- Thu Jul 02 10:33:57 2020 +0000
- Revision:
- 1:af17c65e86dc
- Parent:
- 0:ea88f8c194d2
233
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
turumputum | 0:ea88f8c194d2 | 1 | #include "mbed.h" |
turumputum | 0:ea88f8c194d2 | 2 | #include "PixelArray.h" |
turumputum | 0:ea88f8c194d2 | 3 | #include "WS2812.h" |
turumputum | 0:ea88f8c194d2 | 4 | #include "config.h" |
turumputum | 0:ea88f8c194d2 | 5 | #include "DebounceIn.h" |
turumputum | 0:ea88f8c194d2 | 6 | |
turumputum | 0:ea88f8c194d2 | 7 | |
turumputum | 0:ea88f8c194d2 | 8 | #include "sensor.h" |
turumputum | 0:ea88f8c194d2 | 9 | |
turumputum | 0:ea88f8c194d2 | 10 | //#include "leds.h" |
turumputum | 0:ea88f8c194d2 | 11 | |
turumputum | 0:ea88f8c194d2 | 12 | |
turumputum | 0:ea88f8c194d2 | 13 | Serial pc(USBTX, USBRX); |
turumputum | 0:ea88f8c194d2 | 14 | |
turumputum | 0:ea88f8c194d2 | 15 | |
turumputum | 0:ea88f8c194d2 | 16 | DebounceIn Button_1(PE_0); |
turumputum | 0:ea88f8c194d2 | 17 | DebounceIn Button_2(PE_2); |
turumputum | 0:ea88f8c194d2 | 18 | DebounceIn Button_3(PE_4); |
turumputum | 0:ea88f8c194d2 | 19 | DebounceIn Button_4(PE_6); |
turumputum | 0:ea88f8c194d2 | 20 | |
turumputum | 0:ea88f8c194d2 | 21 | |
turumputum | 0:ea88f8c194d2 | 22 | //__________LEDS DEFINE___________________ |
turumputum | 0:ea88f8c194d2 | 23 | |
turumputum | 0:ea88f8c194d2 | 24 | #define LedOff 0 |
turumputum | 0:ea88f8c194d2 | 25 | #define LedWait 1 |
turumputum | 0:ea88f8c194d2 | 26 | #define LedOn 3 |
turumputum | 0:ea88f8c194d2 | 27 | #define LedBlink 4 |
turumputum | 0:ea88f8c194d2 | 28 | #define LedRun 5 |
turumputum | 0:ea88f8c194d2 | 29 | |
turumputum | 0:ea88f8c194d2 | 30 | #define T0H 20 |
turumputum | 0:ea88f8c194d2 | 31 | #define T0L 105 |
turumputum | 0:ea88f8c194d2 | 32 | #define T1H 70 |
turumputum | 0:ea88f8c194d2 | 33 | #define T1L 123 |
turumputum | 0:ea88f8c194d2 | 34 | |
turumputum | 0:ea88f8c194d2 | 35 | #define idle 4 |
turumputum | 0:ea88f8c194d2 | 36 | #define rasta 1 |
turumputum | 0:ea88f8c194d2 | 37 | #define bio 2 |
turumputum | 0:ea88f8c194d2 | 38 | #define bacterium 3 |
turumputum | 0:ea88f8c194d2 | 39 | |
turumputum | 0:ea88f8c194d2 | 40 | |
turumputum | 0:ea88f8c194d2 | 41 | |
turumputum | 0:ea88f8c194d2 | 42 | //__________TABLE DEFINE___________________ |
turumputum | 0:ea88f8c194d2 | 43 | |
turumputum | 0:ea88f8c194d2 | 44 | |
turumputum | 0:ea88f8c194d2 | 45 | uint8_t tableState[4][30]= { |
turumputum | 0:ea88f8c194d2 | 46 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29}, //num of sensor |
turumputum | 0:ea88f8c194d2 | 47 | {0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //sensor state |
turumputum | 0:ea88f8c194d2 | 48 | {0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //lype of light |
turumputum | 0:ea88f8c194d2 | 49 | {0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} //intence or progress |
turumputum | 0:ea88f8c194d2 | 50 | }; |
turumputum | 0:ea88f8c194d2 | 51 | |
turumputum | 0:ea88f8c194d2 | 52 | |
turumputum | 0:ea88f8c194d2 | 53 | uint8_t gameRule[5][34]= { |
turumputum | 0:ea88f8c194d2 | 54 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29, 0, 0, 0, 0}, //num of sensor |
turumputum | 0:ea88f8c194d2 | 55 | {1,1,1,1,1,1,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0,255, 0, 27}, //rasta |
turumputum | 0:ea88f8c194d2 | 56 | {0,0,0,0,0,0,0,0,0,0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0,200,100, 0, 16}, //bio |
turumputum | 0:ea88f8c194d2 | 57 | {1,1,1,1,1,1,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0,200,200, 22}, //bacterium |
turumputum | 0:ea88f8c194d2 | 58 | {0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,150,150,150} //idle |
turumputum | 0:ea88f8c194d2 | 59 | }; |
turumputum | 0:ea88f8c194d2 | 60 | |
turumputum | 0:ea88f8c194d2 | 61 | |
turumputum | 0:ea88f8c194d2 | 62 | #define frontSize 5 |
turumputum | 0:ea88f8c194d2 | 63 | float front[frontSize] = {0.0,0.01,0.40,0.01,0.0}; |
turumputum | 0:ea88f8c194d2 | 64 | |
turumputum | 0:ea88f8c194d2 | 65 | |
turumputum | 0:ea88f8c194d2 | 66 | int color_set(uint8_t red,uint8_t green, uint8_t blue); |
turumputum | 0:ea88f8c194d2 | 67 | void startUp_Led(); |
turumputum | 0:ea88f8c194d2 | 68 | void fadeEffect(); |
turumputum | 0:ea88f8c194d2 | 69 | void lightLeds(); |
turumputum | 0:ea88f8c194d2 | 70 | void setLedRule(int mode); |
turumputum | 0:ea88f8c194d2 | 71 | void setStaticValToLed(int type,int __sp1, int __size1, int __sp2, int __size2, int r, int g, int b); |
turumputum | 1:af17c65e86dc | 72 | void buttonLight(int b2, int b3, int b4); |
turumputum | 0:ea88f8c194d2 | 73 | void writeStenksLeds(); |
turumputum | 0:ea88f8c194d2 | 74 | |
turumputum | 0:ea88f8c194d2 | 75 | |
turumputum | 0:ea88f8c194d2 | 76 | //___________________Classes__________________________ |
turumputum | 0:ea88f8c194d2 | 77 | class LedGroupInside |
turumputum | 0:ea88f8c194d2 | 78 | { |
turumputum | 0:ea88f8c194d2 | 79 | public: |
turumputum | 0:ea88f8c194d2 | 80 | LedGroupInside(PinName pin, int placeInTable, int size); |
turumputum | 0:ea88f8c194d2 | 81 | //~LedGroup(); |
turumputum | 0:ea88f8c194d2 | 82 | void light(int mode); |
turumputum | 0:ea88f8c194d2 | 83 | private: |
turumputum | 0:ea88f8c194d2 | 84 | PinName __outPin; |
turumputum | 0:ea88f8c194d2 | 85 | int __mode; |
turumputum | 0:ea88f8c194d2 | 86 | int __placeInTable; |
turumputum | 0:ea88f8c194d2 | 87 | int __size; |
turumputum | 0:ea88f8c194d2 | 88 | PixelArray __pa; |
turumputum | 0:ea88f8c194d2 | 89 | WS2812 __leds; |
turumputum | 0:ea88f8c194d2 | 90 | }; |
turumputum | 0:ea88f8c194d2 | 91 | |
turumputum | 0:ea88f8c194d2 | 92 | class LedGroupStenka |
turumputum | 0:ea88f8c194d2 | 93 | { |
turumputum | 0:ea88f8c194d2 | 94 | public: |
turumputum | 0:ea88f8c194d2 | 95 | LedGroupStenka(int placeInTable, int type, int sp1, int size1, int sp2, int size2); |
turumputum | 0:ea88f8c194d2 | 96 | //~LedGroup(); |
turumputum | 0:ea88f8c194d2 | 97 | void light(int mode); |
turumputum | 0:ea88f8c194d2 | 98 | private: |
turumputum | 0:ea88f8c194d2 | 99 | void writeLed(int type, uint8_t r, uint8_t g, uint8_t b); |
turumputum | 0:ea88f8c194d2 | 100 | PinName __outPin; |
turumputum | 0:ea88f8c194d2 | 101 | int __type; |
turumputum | 0:ea88f8c194d2 | 102 | int __sp1, __size1; |
turumputum | 0:ea88f8c194d2 | 103 | int __sp2, __size2; |
turumputum | 0:ea88f8c194d2 | 104 | int __mode; |
turumputum | 0:ea88f8c194d2 | 105 | int __placeInTable; |
turumputum | 0:ea88f8c194d2 | 106 | int __size; |
turumputum | 0:ea88f8c194d2 | 107 | }; |
turumputum | 0:ea88f8c194d2 | 108 | |
turumputum | 0:ea88f8c194d2 | 109 | //__________________Config_LEDS_____________________________________ |
turumputum | 0:ea88f8c194d2 | 110 | #define numOfLed_stenkaLed_1 177 |
turumputum | 0:ea88f8c194d2 | 111 | PixelArray pa_stenkaLed_1(numOfLed_stenkaLed_1); |
turumputum | 0:ea88f8c194d2 | 112 | WS2812 stenkaLed_1(PF_0, numOfLed_stenkaLed_1, T0H, T0L, T1H, T1L); |
turumputum | 0:ea88f8c194d2 | 113 | |
turumputum | 0:ea88f8c194d2 | 114 | #define numOfLed_stenkaLed_2 156 |
turumputum | 0:ea88f8c194d2 | 115 | PixelArray pa_stenkaLed_2(numOfLed_stenkaLed_2); |
turumputum | 0:ea88f8c194d2 | 116 | WS2812 stenkaLed_2(PF_1, numOfLed_stenkaLed_2, T0H, T0L, T1H, T1L); |
turumputum | 0:ea88f8c194d2 | 117 | |
turumputum | 0:ea88f8c194d2 | 118 | # define numOfLed_stenkaLed_3 137 |
turumputum | 0:ea88f8c194d2 | 119 | PixelArray pa_stenkaLed_3(numOfLed_stenkaLed_3); |
turumputum | 0:ea88f8c194d2 | 120 | WS2812 stenkaLed_3(PF_2, numOfLed_stenkaLed_3, T0H, T0L, T1H, T1L); |
turumputum | 0:ea88f8c194d2 | 121 | |
turumputum | 0:ea88f8c194d2 | 122 | //LedGroupStenka(int placeInTable,int type, int sp1, int size1, int sp2, int size2) |
turumputum | 0:ea88f8c194d2 | 123 | LedGroupStenka membLed_y1(10,2, 0, 21, 0, 25); |
turumputum | 0:ea88f8c194d2 | 124 | LedGroupStenka membLed_s2(11,0, 9, 9, 9, 9); |
turumputum | 0:ea88f8c194d2 | 125 | LedGroupStenka membLed_s3(12,0, 18, 9, 18, 9); |
turumputum | 0:ea88f8c194d2 | 126 | LedGroupStenka membLed_y4(13,0, 27, 21, 27, 26); |
turumputum | 0:ea88f8c194d2 | 127 | LedGroupStenka membLed_s5(14,0, 48, 8, 53, 8); |
turumputum | 0:ea88f8c194d2 | 128 | LedGroupStenka membLed_y6(15,0, 56, 21, 61, 26); |
turumputum | 0:ea88f8c194d2 | 129 | LedGroupStenka membLed_s7(16,0, 77, 9, 87, 9); |
turumputum | 0:ea88f8c194d2 | 130 | LedGroupStenka membLed_s8(17,0, 86, 9, 96, 9); |
turumputum | 0:ea88f8c194d2 | 131 | LedGroupStenka membLed_y9(18,0, 95, 21, 105, 26); |
turumputum | 0:ea88f8c194d2 | 132 | LedGroupStenka membLed_s10(19,0, 116, 9, 131, 9); |
turumputum | 0:ea88f8c194d2 | 133 | |
turumputum | 0:ea88f8c194d2 | 134 | LedGroupStenka stenkaLed_y1(0,3, 0, 31, 0, 25); |
turumputum | 0:ea88f8c194d2 | 135 | LedGroupStenka stenkaLed_s2(1,1, 9, 9, 9, 9); |
turumputum | 0:ea88f8c194d2 | 136 | LedGroupStenka stenkaLed_s3(2,1, 18, 9, 18, 9); |
turumputum | 0:ea88f8c194d2 | 137 | LedGroupStenka stenkaLed_y4(3,1, 27, 31, 27, 26); |
turumputum | 0:ea88f8c194d2 | 138 | LedGroupStenka stenkaLed_s5(4,1, 58, 8, 53, 8); |
turumputum | 0:ea88f8c194d2 | 139 | LedGroupStenka stenkaLed_y6(5,1, 66, 31, 61, 26); |
turumputum | 0:ea88f8c194d2 | 140 | LedGroupStenka stenkaLed_s7(6,1, 97, 9, 87, 9); |
turumputum | 0:ea88f8c194d2 | 141 | LedGroupStenka stenkaLed_s8(7,1, 106, 9, 96, 9); |
turumputum | 0:ea88f8c194d2 | 142 | LedGroupStenka stenkaLed_y9(8,1, 115, 32, 105, 26); |
turumputum | 0:ea88f8c194d2 | 143 | LedGroupStenka stenkaLed_s10(9,1, 147, 9, 131, 9); |
turumputum | 0:ea88f8c194d2 | 144 | |
turumputum | 0:ea88f8c194d2 | 145 | LedGroupInside lizosomaLed(PF_3, 25, 50); |
turumputum | 0:ea88f8c194d2 | 146 | LedGroupInside nucleoidLed(PF_4, 29, 50); |
turumputum | 0:ea88f8c194d2 | 147 | LedGroupInside yadroLed(PF_5,20,50); |
turumputum | 0:ea88f8c194d2 | 148 | LedGroupInside ribosomaLed(PF_6, 28, 40); |
turumputum | 0:ea88f8c194d2 | 149 | LedGroupInside goldgiLed(PF_7, 26, 40); |
turumputum | 0:ea88f8c194d2 | 150 | LedGroupInside endoplazmaLed(PF_8, 22, 50); |
turumputum | 0:ea88f8c194d2 | 151 | LedGroupInside plastidaLed(PF_9, 23, 50); |
turumputum | 0:ea88f8c194d2 | 152 | LedGroupInside centorLed(PF_10, 27, 30); |
turumputum | 0:ea88f8c194d2 | 153 | LedGroupInside mitohondriyaLed(PF_11, 21, 50); |
turumputum | 0:ea88f8c194d2 | 154 | LedGroupInside vacuolLed(PF_12, 24, 45); |
turumputum | 0:ea88f8c194d2 | 155 | |
turumputum | 0:ea88f8c194d2 | 156 | //_____________Config Button LEDS____________________ |
turumputum | 0:ea88f8c194d2 | 157 | PixelArray pa_ButtonLed_1(1); |
turumputum | 0:ea88f8c194d2 | 158 | WS2812 ButtonLed_1(PE_1, 1, T0H, T0L, T1H, T1L); |
turumputum | 0:ea88f8c194d2 | 159 | |
turumputum | 0:ea88f8c194d2 | 160 | PixelArray pa_ButtonLed_2(1); |
turumputum | 0:ea88f8c194d2 | 161 | WS2812 ButtonLed_2(PE_3, 1, T0H, T0L, T1H, T1L); |
turumputum | 0:ea88f8c194d2 | 162 | |
turumputum | 0:ea88f8c194d2 | 163 | |
turumputum | 0:ea88f8c194d2 | 164 | PixelArray pa_ButtonLed_3(1); |
turumputum | 0:ea88f8c194d2 | 165 | WS2812 ButtonLed_3(PE_5, 1, T0H, T0L, T1H, T1L); |
turumputum | 0:ea88f8c194d2 | 166 | |
turumputum | 0:ea88f8c194d2 | 167 | |
turumputum | 0:ea88f8c194d2 | 168 | PixelArray pa_ButtonLed_4(1); |
turumputum | 0:ea88f8c194d2 | 169 | WS2812 ButtonLed_4(PE_7, 1, T0H, T0L, T1H, T1L); |
turumputum | 0:ea88f8c194d2 | 170 | |
turumputum | 0:ea88f8c194d2 | 171 | |
turumputum | 0:ea88f8c194d2 | 172 | |
turumputum | 0:ea88f8c194d2 | 173 | //__________BUTTONS DEFINE___________________ |
turumputum | 0:ea88f8c194d2 | 174 | |
turumputum | 0:ea88f8c194d2 | 175 | |
turumputum | 0:ea88f8c194d2 | 176 | |
turumputum | 0:ea88f8c194d2 | 177 | |
turumputum | 0:ea88f8c194d2 | 178 | |
turumputum | 0:ea88f8c194d2 | 179 |