![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
This is how i got the hardware to work. Not saying that it cant work any other way. I haven't tied anything of yours in. So likely delete mine from rev 2 or 3, and then put this instead. Then it might work.
Dependencies: mbed
main.cpp@0:c426396d5fdf, 2017-06-22 (annotated)
- Committer:
- PET
- Date:
- Thu Jun 22 04:45:01 2017 +0000
- Revision:
- 0:c426396d5fdf
If you wanted to work on it, or look at it.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PET | 0:c426396d5fdf | 1 | #include "mbed.h" |
PET | 0:c426396d5fdf | 2 | #include "rgb_led.h" |
PET | 0:c426396d5fdf | 3 | |
PET | 0:c426396d5fdf | 4 | /* |
PET | 0:c426396d5fdf | 5 | - number[] is the 3 digits. [0] is the digit for the letter L or H, and needs |
PET | 0:c426396d5fdf | 6 | to be a 0 or a 1, for the display to light up. |
PET | 0:c426396d5fdf | 7 | - number[1] is the 'tens', number [2] is the 'ones'. |
PET | 0:c426396d5fdf | 8 | - The program takes care of the transistor count itself. So no need to |
PET | 0:c426396d5fdf | 9 | send anything for that to the Ticker any longer. Now only the digits needs |
PET | 0:c426396d5fdf | 10 | to be placed in number. |
PET | 0:c426396d5fdf | 11 | - I got the ticker to work out here. Not in .h etc. |
PET | 0:c426396d5fdf | 12 | - And I am fairly sure it says somewhere in the big white programming book |
PET | 0:c426396d5fdf | 13 | that a enum starts from 1. However here it starts at 0. Så status needs to |
PET | 0:c426396d5fdf | 14 | subtracted a 1, before it gets send to the function below. (RGB...). |
PET | 0:c426396d5fdf | 15 | */ |
PET | 0:c426396d5fdf | 16 | |
PET | 0:c426396d5fdf | 17 | DigitalOut Dig_1(PB_6); |
PET | 0:c426396d5fdf | 18 | DigitalOut Dig_2(PC_7); |
PET | 0:c426396d5fdf | 19 | DigitalOut Dig_3(PA_9); |
PET | 0:c426396d5fdf | 20 | DigitalOut Seg_A(PA_7); //original design says PA_3. I think there is a button |
PET | 0:c426396d5fdf | 21 | DigitalOut Seg_B(PA_10);// here (PA_7). |
PET | 0:c426396d5fdf | 22 | DigitalOut Seg_C(PB_3); |
PET | 0:c426396d5fdf | 23 | DigitalOut Seg_D(PB_5); |
PET | 0:c426396d5fdf | 24 | DigitalOut Seg_E(PB_4); |
PET | 0:c426396d5fdf | 25 | DigitalOut Seg_F(PB_10); |
PET | 0:c426396d5fdf | 26 | DigitalOut Seg_G(PA_8); |
PET | 0:c426396d5fdf | 27 | |
PET | 0:c426396d5fdf | 28 | int number[3] = {0, 0, 0}; |
PET | 0:c426396d5fdf | 29 | int dig = 0; |
PET | 0:c426396d5fdf | 30 | int status; |
PET | 0:c426396d5fdf | 31 | |
PET | 0:c426396d5fdf | 32 | void rgb_outp(int status); |
PET | 0:c426396d5fdf | 33 | void output(); |
PET | 0:c426396d5fdf | 34 | |
PET | 0:c426396d5fdf | 35 | Ticker output_ticker; |
PET | 0:c426396d5fdf | 36 | |
PET | 0:c426396d5fdf | 37 | main() |
PET | 0:c426396d5fdf | 38 | { |
PET | 0:c426396d5fdf | 39 | int i; |
PET | 0:c426396d5fdf | 40 | output_ticker.attach(&output, 0.001); |
PET | 0:c426396d5fdf | 41 | |
PET | 0:c426396d5fdf | 42 | for(i = 0; i < 11; i++) // Would need deletion from here.. |
PET | 0:c426396d5fdf | 43 | { |
PET | 0:c426396d5fdf | 44 | if(i > 9) |
PET | 0:c426396d5fdf | 45 | { |
PET | 0:c426396d5fdf | 46 | i = 1; |
PET | 0:c426396d5fdf | 47 | }; |
PET | 0:c426396d5fdf | 48 | |
PET | 0:c426396d5fdf | 49 | number[0]++; |
PET | 0:c426396d5fdf | 50 | if(number[0] > 9) |
PET | 0:c426396d5fdf | 51 | { |
PET | 0:c426396d5fdf | 52 | status = 0; |
PET | 0:c426396d5fdf | 53 | rgb_outp(status); |
PET | 0:c426396d5fdf | 54 | number[0] = 0; |
PET | 0:c426396d5fdf | 55 | number[1]++; |
PET | 0:c426396d5fdf | 56 | if(number[1] > 9) |
PET | 0:c426396d5fdf | 57 | { |
PET | 0:c426396d5fdf | 58 | status = 4; |
PET | 0:c426396d5fdf | 59 | rgb_outp(status); |
PET | 0:c426396d5fdf | 60 | number[1] = 0; |
PET | 0:c426396d5fdf | 61 | number[2]++; |
PET | 0:c426396d5fdf | 62 | } |
PET | 0:c426396d5fdf | 63 | } |
PET | 0:c426396d5fdf | 64 | if((number[0] == 9) && (number[1] == 9) && (number[2] == 9)) |
PET | 0:c426396d5fdf | 65 | { |
PET | 0:c426396d5fdf | 66 | number[0] = 0; |
PET | 0:c426396d5fdf | 67 | number[1] = 0; |
PET | 0:c426396d5fdf | 68 | number[2] = 0; |
PET | 0:c426396d5fdf | 69 | } |
PET | 0:c426396d5fdf | 70 | |
PET | 0:c426396d5fdf | 71 | |
PET | 0:c426396d5fdf | 72 | wait(0.2); |
PET | 0:c426396d5fdf | 73 | } // until here. |
PET | 0:c426396d5fdf | 74 | } |
PET | 0:c426396d5fdf | 75 | |
PET | 0:c426396d5fdf | 76 | void output() |
PET | 0:c426396d5fdf | 77 | { |
PET | 0:c426396d5fdf | 78 | int out_value; |
PET | 0:c426396d5fdf | 79 | |
PET | 0:c426396d5fdf | 80 | dig++; |
PET | 0:c426396d5fdf | 81 | if(dig == 4) |
PET | 0:c426396d5fdf | 82 | { |
PET | 0:c426396d5fdf | 83 | dig = 1; |
PET | 0:c426396d5fdf | 84 | } |
PET | 0:c426396d5fdf | 85 | |
PET | 0:c426396d5fdf | 86 | switch(dig) |
PET | 0:c426396d5fdf | 87 | { |
PET | 0:c426396d5fdf | 88 | case 1: |
PET | 0:c426396d5fdf | 89 | Dig_1 = 0; |
PET | 0:c426396d5fdf | 90 | Dig_2 = 0; |
PET | 0:c426396d5fdf | 91 | Dig_3 = 1; |
PET | 0:c426396d5fdf | 92 | out_value = number[0]; |
PET | 0:c426396d5fdf | 93 | break; |
PET | 0:c426396d5fdf | 94 | case 2: |
PET | 0:c426396d5fdf | 95 | Dig_1 = 0; |
PET | 0:c426396d5fdf | 96 | Dig_2 = 1; |
PET | 0:c426396d5fdf | 97 | Dig_3 = 0; |
PET | 0:c426396d5fdf | 98 | out_value = number[1]; |
PET | 0:c426396d5fdf | 99 | break; |
PET | 0:c426396d5fdf | 100 | case 3: |
PET | 0:c426396d5fdf | 101 | Dig_1 = 1; |
PET | 0:c426396d5fdf | 102 | Dig_2 = 0; |
PET | 0:c426396d5fdf | 103 | Dig_3 = 0; |
PET | 0:c426396d5fdf | 104 | if(number[2] == 0) |
PET | 0:c426396d5fdf | 105 | { |
PET | 0:c426396d5fdf | 106 | out_value = 20; |
PET | 0:c426396d5fdf | 107 | } |
PET | 0:c426396d5fdf | 108 | else if(number[2] == 1) |
PET | 0:c426396d5fdf | 109 | { |
PET | 0:c426396d5fdf | 110 | out_value = 30; |
PET | 0:c426396d5fdf | 111 | } |
PET | 0:c426396d5fdf | 112 | else |
PET | 0:c426396d5fdf | 113 | { |
PET | 0:c426396d5fdf | 114 | Dig_1 = 0; |
PET | 0:c426396d5fdf | 115 | Dig_2 = 0; |
PET | 0:c426396d5fdf | 116 | Dig_3 = 0; |
PET | 0:c426396d5fdf | 117 | } |
PET | 0:c426396d5fdf | 118 | break; |
PET | 0:c426396d5fdf | 119 | default: |
PET | 0:c426396d5fdf | 120 | Dig_1 = 0; |
PET | 0:c426396d5fdf | 121 | Dig_2 = 0; |
PET | 0:c426396d5fdf | 122 | Dig_3 = 0; |
PET | 0:c426396d5fdf | 123 | out_value = 0; |
PET | 0:c426396d5fdf | 124 | } |
PET | 0:c426396d5fdf | 125 | |
PET | 0:c426396d5fdf | 126 | switch(out_value) |
PET | 0:c426396d5fdf | 127 | { |
PET | 0:c426396d5fdf | 128 | case 0: |
PET | 0:c426396d5fdf | 129 | Seg_A = 0; |
PET | 0:c426396d5fdf | 130 | Seg_B = 0; |
PET | 0:c426396d5fdf | 131 | Seg_C = 0; |
PET | 0:c426396d5fdf | 132 | Seg_D = 0; |
PET | 0:c426396d5fdf | 133 | Seg_E = 0; |
PET | 0:c426396d5fdf | 134 | Seg_F = 0; |
PET | 0:c426396d5fdf | 135 | Seg_G = 1; |
PET | 0:c426396d5fdf | 136 | break; |
PET | 0:c426396d5fdf | 137 | case 1: |
PET | 0:c426396d5fdf | 138 | Seg_A = 1; |
PET | 0:c426396d5fdf | 139 | Seg_B = 0; |
PET | 0:c426396d5fdf | 140 | Seg_C = 0; |
PET | 0:c426396d5fdf | 141 | Seg_D = 1; |
PET | 0:c426396d5fdf | 142 | Seg_E = 1; |
PET | 0:c426396d5fdf | 143 | Seg_F = 1; |
PET | 0:c426396d5fdf | 144 | Seg_G = 1; |
PET | 0:c426396d5fdf | 145 | break; |
PET | 0:c426396d5fdf | 146 | case 2: |
PET | 0:c426396d5fdf | 147 | Seg_A = 0; |
PET | 0:c426396d5fdf | 148 | Seg_B = 0; |
PET | 0:c426396d5fdf | 149 | Seg_C = 1; |
PET | 0:c426396d5fdf | 150 | Seg_D = 0; |
PET | 0:c426396d5fdf | 151 | Seg_E = 0; |
PET | 0:c426396d5fdf | 152 | Seg_F = 1; |
PET | 0:c426396d5fdf | 153 | Seg_G = 0; |
PET | 0:c426396d5fdf | 154 | break; |
PET | 0:c426396d5fdf | 155 | case 3: |
PET | 0:c426396d5fdf | 156 | Seg_A = 0; |
PET | 0:c426396d5fdf | 157 | Seg_B = 0; |
PET | 0:c426396d5fdf | 158 | Seg_C = 0; |
PET | 0:c426396d5fdf | 159 | Seg_D = 0; |
PET | 0:c426396d5fdf | 160 | Seg_E = 1; |
PET | 0:c426396d5fdf | 161 | Seg_F = 1; |
PET | 0:c426396d5fdf | 162 | Seg_G = 0; |
PET | 0:c426396d5fdf | 163 | break; |
PET | 0:c426396d5fdf | 164 | case 4: |
PET | 0:c426396d5fdf | 165 | Seg_A = 1; |
PET | 0:c426396d5fdf | 166 | Seg_B = 0; |
PET | 0:c426396d5fdf | 167 | Seg_C = 0; |
PET | 0:c426396d5fdf | 168 | Seg_D = 1; |
PET | 0:c426396d5fdf | 169 | Seg_E = 1; |
PET | 0:c426396d5fdf | 170 | Seg_F = 0; |
PET | 0:c426396d5fdf | 171 | Seg_G = 0; |
PET | 0:c426396d5fdf | 172 | break; |
PET | 0:c426396d5fdf | 173 | case 5: |
PET | 0:c426396d5fdf | 174 | Seg_A = 0; |
PET | 0:c426396d5fdf | 175 | Seg_B = 1; |
PET | 0:c426396d5fdf | 176 | Seg_C = 0; |
PET | 0:c426396d5fdf | 177 | Seg_D = 0; |
PET | 0:c426396d5fdf | 178 | Seg_E = 1; |
PET | 0:c426396d5fdf | 179 | Seg_F = 0; |
PET | 0:c426396d5fdf | 180 | Seg_G = 0; |
PET | 0:c426396d5fdf | 181 | break; |
PET | 0:c426396d5fdf | 182 | case 6: |
PET | 0:c426396d5fdf | 183 | Seg_A = 0; |
PET | 0:c426396d5fdf | 184 | Seg_B = 1; |
PET | 0:c426396d5fdf | 185 | Seg_C = 0; |
PET | 0:c426396d5fdf | 186 | Seg_D = 0; |
PET | 0:c426396d5fdf | 187 | Seg_E = 0; |
PET | 0:c426396d5fdf | 188 | Seg_F = 0; |
PET | 0:c426396d5fdf | 189 | Seg_G = 0; |
PET | 0:c426396d5fdf | 190 | break; |
PET | 0:c426396d5fdf | 191 | case 7: |
PET | 0:c426396d5fdf | 192 | Seg_A = 0; |
PET | 0:c426396d5fdf | 193 | Seg_B = 0; |
PET | 0:c426396d5fdf | 194 | Seg_C = 0; |
PET | 0:c426396d5fdf | 195 | Seg_D = 1; |
PET | 0:c426396d5fdf | 196 | Seg_E = 1; |
PET | 0:c426396d5fdf | 197 | Seg_F = 1; |
PET | 0:c426396d5fdf | 198 | Seg_G = 1; |
PET | 0:c426396d5fdf | 199 | break; |
PET | 0:c426396d5fdf | 200 | case 8: |
PET | 0:c426396d5fdf | 201 | Seg_A = 0; |
PET | 0:c426396d5fdf | 202 | Seg_B = 0; |
PET | 0:c426396d5fdf | 203 | Seg_C = 0; |
PET | 0:c426396d5fdf | 204 | Seg_D = 0; |
PET | 0:c426396d5fdf | 205 | Seg_E = 0; |
PET | 0:c426396d5fdf | 206 | Seg_F = 0; |
PET | 0:c426396d5fdf | 207 | Seg_G = 0; |
PET | 0:c426396d5fdf | 208 | break; |
PET | 0:c426396d5fdf | 209 | case 9: |
PET | 0:c426396d5fdf | 210 | Seg_A = 0; |
PET | 0:c426396d5fdf | 211 | Seg_B = 0; |
PET | 0:c426396d5fdf | 212 | Seg_C = 0; |
PET | 0:c426396d5fdf | 213 | Seg_D = 0; |
PET | 0:c426396d5fdf | 214 | Seg_E = 1; |
PET | 0:c426396d5fdf | 215 | Seg_F = 0; |
PET | 0:c426396d5fdf | 216 | Seg_G = 0; |
PET | 0:c426396d5fdf | 217 | break; |
PET | 0:c426396d5fdf | 218 | case 20: |
PET | 0:c426396d5fdf | 219 | Seg_A = 1; |
PET | 0:c426396d5fdf | 220 | Seg_B = 1; |
PET | 0:c426396d5fdf | 221 | Seg_C = 1; |
PET | 0:c426396d5fdf | 222 | Seg_D = 0; |
PET | 0:c426396d5fdf | 223 | Seg_E = 0; |
PET | 0:c426396d5fdf | 224 | Seg_F = 0; |
PET | 0:c426396d5fdf | 225 | Seg_G = 1; |
PET | 0:c426396d5fdf | 226 | break; |
PET | 0:c426396d5fdf | 227 | case 30: |
PET | 0:c426396d5fdf | 228 | Seg_A = 1; |
PET | 0:c426396d5fdf | 229 | Seg_B = 0; |
PET | 0:c426396d5fdf | 230 | Seg_C = 0; |
PET | 0:c426396d5fdf | 231 | Seg_D = 1; |
PET | 0:c426396d5fdf | 232 | Seg_E = 0; |
PET | 0:c426396d5fdf | 233 | Seg_F = 0; |
PET | 0:c426396d5fdf | 234 | Seg_G = 0; |
PET | 0:c426396d5fdf | 235 | break; |
PET | 0:c426396d5fdf | 236 | default: |
PET | 0:c426396d5fdf | 237 | Seg_A = 1; |
PET | 0:c426396d5fdf | 238 | Seg_B = 1; |
PET | 0:c426396d5fdf | 239 | Seg_C = 1; |
PET | 0:c426396d5fdf | 240 | Seg_D = 1; |
PET | 0:c426396d5fdf | 241 | Seg_E = 1; |
PET | 0:c426396d5fdf | 242 | Seg_F = 1; |
PET | 0:c426396d5fdf | 243 | Seg_G = 1; |
PET | 0:c426396d5fdf | 244 | } |
PET | 0:c426396d5fdf | 245 | } |
PET | 0:c426396d5fdf | 246 | |
PET | 0:c426396d5fdf | 247 | void rgb_outp(int status) |
PET | 0:c426396d5fdf | 248 | { |
PET | 0:c426396d5fdf | 249 | RGB_LED lamp(PB_13,PB_14, PB_15); // Creates an object out of the class RGB_LED. |
PET | 0:c426396d5fdf | 250 | // Connect pins on the Nucleo, to the pins the |
PET | 0:c426396d5fdf | 251 | // class. |
PET | 0:c426396d5fdf | 252 | |
PET | 0:c426396d5fdf | 253 | enum colour // Enumeration is used only for making the program more |
PET | 0:c426396d5fdf | 254 | { // easily readable. |
PET | 0:c426396d5fdf | 255 | green, // Is alike an int, starts at green = 1, |
PET | 0:c426396d5fdf | 256 | orange, // orange = 2 etc. |
PET | 0:c426396d5fdf | 257 | red, |
PET | 0:c426396d5fdf | 258 | red_blink, |
PET | 0:c426396d5fdf | 259 | blue |
PET | 0:c426396d5fdf | 260 | }; |
PET | 0:c426396d5fdf | 261 | |
PET | 0:c426396d5fdf | 262 | colour RGB_out = static_cast<colour>(status); |
PET | 0:c426396d5fdf | 263 | // Taking the value from the sensors and change them the enum type. |
PET | 0:c426396d5fdf | 264 | // Enum is somewhat akin to an int already, but RGB_out != status.. |
PET | 0:c426396d5fdf | 265 | |
PET | 0:c426396d5fdf | 266 | switch(RGB_out) |
PET | 0:c426396d5fdf | 267 | { |
PET | 0:c426396d5fdf | 268 | case green: |
PET | 0:c426396d5fdf | 269 | lamp.set(0.0f, 0.0f, 1.0f); |
PET | 0:c426396d5fdf | 270 | break; |
PET | 0:c426396d5fdf | 271 | case orange: |
PET | 0:c426396d5fdf | 272 | lamp.set(1.0f, 1.0f, 0.0f); |
PET | 0:c426396d5fdf | 273 | break; |
PET | 0:c426396d5fdf | 274 | case red: |
PET | 0:c426396d5fdf | 275 | lamp.set(1.0f, 0.0f, 0.0f); |
PET | 0:c426396d5fdf | 276 | break; |
PET | 0:c426396d5fdf | 277 | case red_blink: |
PET | 0:c426396d5fdf | 278 | lamp.flash(1.0f, 0.5f, 1.0f, 0.0f, 1.0f, 0.0f); |
PET | 0:c426396d5fdf | 279 | // On for 50% of every 1 seconds. |
PET | 0:c426396d5fdf | 280 | break; |
PET | 0:c426396d5fdf | 281 | case blue: |
PET | 0:c426396d5fdf | 282 | lamp.flash(1.0f, 0.0f, 0.5f, 0.5f, 0.5f, 0.5f); |
PET | 0:c426396d5fdf | 283 | // On for 50% of every 0.5 seconds. |
PET | 0:c426396d5fdf | 284 | break; |
PET | 0:c426396d5fdf | 285 | default: // Error has occured, blue. Could just have defaulted instead |
PET | 0:c426396d5fdf | 286 | lamp.set(1.0f, 1.0f, 1.0f); // of case blue, however as it is an |
PET | 0:c426396d5fdf | 287 | } |
PET | 0:c426396d5fdf | 288 | |
PET | 0:c426396d5fdf | 289 | return; |
PET | 0:c426396d5fdf | 290 | } |