![](/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@4:eea1a71b9a11, 2014-09-05 (annotated)
- Committer:
- mikewebkist
- Date:
- Fri Sep 05 02:06:56 2014 +0000
- Revision:
- 4:eea1a71b9a11
- Parent:
- 3:f3e484ae4439
- Child:
- 5:48b81f5fd186
add gray code mode and factor out sweep
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 | 4:eea1a71b9a11 | 24 | int main() |
mikewebkist | 4:eea1a71b9a11 | 25 | { |
mikewebkist | 4:eea1a71b9a11 | 26 | while(1) |
mikewebkist | 4:eea1a71b9a11 | 27 | { |
mikewebkist | 4:eea1a71b9a11 | 28 | sweep(0.05); |
mikewebkist | 3:f3e484ae4439 | 29 | for(int n=0; n<128; n++) { |
mikewebkist | 3:f3e484ae4439 | 30 | for(int b=0; b<7; b++) { |
mikewebkist | 3:f3e484ae4439 | 31 | if(n & (1 << b)) { |
mikewebkist | 3:f3e484ae4439 | 32 | LED[6 - b]=1; |
mikewebkist | 3:f3e484ae4439 | 33 | } |
mikewebkist | 3:f3e484ae4439 | 34 | } |
mikewebkist | 3:f3e484ae4439 | 35 | wait(0.05); |
mikewebkist | 3:f3e484ae4439 | 36 | for(int b=0; b<7; b++) { |
mikewebkist | 3:f3e484ae4439 | 37 | LED[b]=0; |
mikewebkist | 3:f3e484ae4439 | 38 | } |
mikewebkist | 3:f3e484ae4439 | 39 | } |
mikewebkist | 4:eea1a71b9a11 | 40 | sweep(0.05); |
mikewebkist | 3:f3e484ae4439 | 41 | for(int x=0; x<32; x++) { |
mikewebkist | 2:fd6008aa85cd | 42 | rndLED = (int) RNG.getByte() % 8; |
mikewebkist | 2:fd6008aa85cd | 43 | LED[rndLED]=1; |
mikewebkist | 3:f3e484ae4439 | 44 | wait(0.1); |
mikewebkist | 2:fd6008aa85cd | 45 | LED[rndLED]=0; |
mikewebkist | 2:fd6008aa85cd | 46 | } |
mikewebkist | 4:eea1a71b9a11 | 47 | sweep(0.05); |
mikewebkist | 4:eea1a71b9a11 | 48 | for(int n=0; n<128; n++) { |
mikewebkist | 4:eea1a71b9a11 | 49 | int gray = (n >> 1) ^ n; |
mikewebkist | 4:eea1a71b9a11 | 50 | for(int b=0; b<7; b++) { |
mikewebkist | 4:eea1a71b9a11 | 51 | if(gray & (1 << b)) { |
mikewebkist | 4:eea1a71b9a11 | 52 | LED[6 - b]=1; |
mikewebkist | 4:eea1a71b9a11 | 53 | } |
mikewebkist | 4:eea1a71b9a11 | 54 | } |
mikewebkist | 4:eea1a71b9a11 | 55 | wait(0.05); |
mikewebkist | 4:eea1a71b9a11 | 56 | for(int b=0; b<7; b++) { |
mikewebkist | 4:eea1a71b9a11 | 57 | LED[b]=0; |
mikewebkist | 4:eea1a71b9a11 | 58 | } |
mikewebkist | 4:eea1a71b9a11 | 59 | } |
Experiment626 | 0:aa0e1ad88af5 | 60 | } |
Experiment626 | 0:aa0e1ad88af5 | 61 | } |