![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A blinky variation for the mBuino with a bunch of different blink modes, deep-sleeping between iterations.
Dependencies: Crypto RNG mbed WakeUp
Fork of mBuinoBlinky by
mBuino blinky experiments.
main.cpp@5:48b81f5fd186, 2014-09-05 (annotated)
- Committer:
- mikewebkist
- Date:
- Fri Sep 05 02:17:25 2014 +0000
- Revision:
- 5:48b81f5fd186
- Parent:
- 4:eea1a71b9a11
- Child:
- 6:fe79549495e0
factor out modes & tweak timing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Experiment626 | 0:aa0e1ad88af5 | 1 | #include "mbed.h" |
mikewebkist | 2:fd6008aa85cd | 2 | #include "RNG/Random.h" |
Experiment626 | 0:aa0e1ad88af5 | 3 | |
Experiment626 | 0:aa0e1ad88af5 | 4 | DigitalOut LED[] = {(P0_7), (P0_8), (P0_2), (P0_20), (P1_19), (P0_17), (P0_23)};// declare 7 LEDs |
Experiment626 | 0:aa0e1ad88af5 | 5 | |
mikewebkist | 2:fd6008aa85cd | 6 | int rndLED = 0; |
mikewebkist | 2:fd6008aa85cd | 7 | Random RNG = Random(); |
Experiment626 | 0:aa0e1ad88af5 | 8 | |
mikewebkist | 4:eea1a71b9a11 | 9 | void sweep(float delayTime) |
Experiment626 | 0:aa0e1ad88af5 | 10 | { |
mikewebkist | 1:47c61bf9c81e | 11 | for(int x=0; x<7; x++) |
Experiment626 | 0:aa0e1ad88af5 | 12 | { |
mikewebkist | 1:47c61bf9c81e | 13 | LED[x] = 1; |
mikewebkist | 1:47c61bf9c81e | 14 | wait(delayTime); |
Experiment626 | 0:aa0e1ad88af5 | 15 | } |
mikewebkist | 2:fd6008aa85cd | 16 | |
mikewebkist | 2:fd6008aa85cd | 17 | for(int x=6; x>=0; x--) |
Experiment626 | 0:aa0e1ad88af5 | 18 | { |
mikewebkist | 2:fd6008aa85cd | 19 | LED[x] = 0; |
mikewebkist | 1:47c61bf9c81e | 20 | wait(delayTime); |
Experiment626 | 0:aa0e1ad88af5 | 21 | } |
mikewebkist | 4:eea1a71b9a11 | 22 | } |
mikewebkist | 4:eea1a71b9a11 | 23 | |
mikewebkist | 5:48b81f5fd186 | 24 | void randomMode(float delayTime) |
mikewebkist | 4:eea1a71b9a11 | 25 | { |
mikewebkist | 5:48b81f5fd186 | 26 | for(int x=0; x<128; x++) { |
mikewebkist | 5:48b81f5fd186 | 27 | rndLED = (int) RNG.getByte() % 8; |
mikewebkist | 5:48b81f5fd186 | 28 | LED[rndLED]=1; |
mikewebkist | 5:48b81f5fd186 | 29 | wait(delayTime); |
mikewebkist | 5:48b81f5fd186 | 30 | LED[rndLED]=0; |
mikewebkist | 5:48b81f5fd186 | 31 | } |
mikewebkist | 5:48b81f5fd186 | 32 | } |
mikewebkist | 5:48b81f5fd186 | 33 | |
mikewebkist | 5:48b81f5fd186 | 34 | void binaryMode(float delayTime) { |
mikewebkist | 3:f3e484ae4439 | 35 | for(int n=0; n<128; n++) { |
mikewebkist | 3:f3e484ae4439 | 36 | for(int b=0; b<7; b++) { |
mikewebkist | 3:f3e484ae4439 | 37 | if(n & (1 << b)) { |
mikewebkist | 3:f3e484ae4439 | 38 | LED[6 - b]=1; |
mikewebkist | 3:f3e484ae4439 | 39 | } |
mikewebkist | 3:f3e484ae4439 | 40 | } |
mikewebkist | 5:48b81f5fd186 | 41 | wait(delayTime); |
mikewebkist | 3:f3e484ae4439 | 42 | for(int b=0; b<7; b++) { |
mikewebkist | 3:f3e484ae4439 | 43 | LED[b]=0; |
mikewebkist | 3:f3e484ae4439 | 44 | } |
mikewebkist | 3:f3e484ae4439 | 45 | } |
mikewebkist | 5:48b81f5fd186 | 46 | } |
mikewebkist | 5:48b81f5fd186 | 47 | |
mikewebkist | 5:48b81f5fd186 | 48 | void grayMode(float delayTime) { |
mikewebkist | 4:eea1a71b9a11 | 49 | for(int n=0; n<128; n++) { |
mikewebkist | 4:eea1a71b9a11 | 50 | int gray = (n >> 1) ^ n; |
mikewebkist | 4:eea1a71b9a11 | 51 | for(int b=0; b<7; b++) { |
mikewebkist | 4:eea1a71b9a11 | 52 | if(gray & (1 << b)) { |
mikewebkist | 4:eea1a71b9a11 | 53 | LED[6 - b]=1; |
mikewebkist | 4:eea1a71b9a11 | 54 | } |
mikewebkist | 4:eea1a71b9a11 | 55 | } |
mikewebkist | 5:48b81f5fd186 | 56 | wait(delayTime); |
mikewebkist | 4:eea1a71b9a11 | 57 | for(int b=0; b<7; b++) { |
mikewebkist | 4:eea1a71b9a11 | 58 | LED[b]=0; |
mikewebkist | 4:eea1a71b9a11 | 59 | } |
mikewebkist | 4:eea1a71b9a11 | 60 | } |
mikewebkist | 5:48b81f5fd186 | 61 | } |
mikewebkist | 5:48b81f5fd186 | 62 | |
mikewebkist | 5:48b81f5fd186 | 63 | int main() |
mikewebkist | 5:48b81f5fd186 | 64 | { |
mikewebkist | 5:48b81f5fd186 | 65 | while(1) |
mikewebkist | 5:48b81f5fd186 | 66 | { |
mikewebkist | 5:48b81f5fd186 | 67 | sweep(0.05); |
mikewebkist | 5:48b81f5fd186 | 68 | binaryMode(0.05); |
mikewebkist | 5:48b81f5fd186 | 69 | sweep(0.05); |
mikewebkist | 5:48b81f5fd186 | 70 | randomMode(0.025); |
mikewebkist | 5:48b81f5fd186 | 71 | sweep(0.05); |
mikewebkist | 5:48b81f5fd186 | 72 | grayMode(0.05); |
Experiment626 | 0:aa0e1ad88af5 | 73 | } |
Experiment626 | 0:aa0e1ad88af5 | 74 | } |