![](/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@9:7ae675372031, 2014-09-06 (annotated)
- Committer:
- mikewebkist
- Date:
- Sat Sep 06 02:44:07 2014 +0000
- Revision:
- 9:7ae675372031
- Parent:
- 8:41a5757f3bb9
- Child:
- 10:8a901b6d8cfa
new mode: multiSweep
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 | 6:fe79549495e0 | 24 | void bounceMode(float delayTime) |
mikewebkist | 6:fe79549495e0 | 25 | { |
mikewebkist | 6:fe79549495e0 | 26 | for(int x=0; x<7; x++) |
mikewebkist | 6:fe79549495e0 | 27 | { |
mikewebkist | 6:fe79549495e0 | 28 | LED[x] = 1; |
mikewebkist | 6:fe79549495e0 | 29 | wait(delayTime); |
mikewebkist | 6:fe79549495e0 | 30 | LED[x] = 0; |
mikewebkist | 6:fe79549495e0 | 31 | } |
mikewebkist | 6:fe79549495e0 | 32 | |
mikewebkist | 6:fe79549495e0 | 33 | for(int x=6; x>=0; x--) |
mikewebkist | 6:fe79549495e0 | 34 | { |
mikewebkist | 6:fe79549495e0 | 35 | LED[x] = 1; |
mikewebkist | 6:fe79549495e0 | 36 | wait(delayTime); |
mikewebkist | 6:fe79549495e0 | 37 | LED[x] = 0; |
mikewebkist | 6:fe79549495e0 | 38 | } |
mikewebkist | 6:fe79549495e0 | 39 | } |
mikewebkist | 6:fe79549495e0 | 40 | |
mikewebkist | 9:7ae675372031 | 41 | void multiSweepMode(float delayTime) |
mikewebkist | 9:7ae675372031 | 42 | { |
mikewebkist | 9:7ae675372031 | 43 | for(int w=1; w<13; w++) |
mikewebkist | 9:7ae675372031 | 44 | { |
mikewebkist | 9:7ae675372031 | 45 | for(int x=1-w; x<13; x++) |
mikewebkist | 9:7ae675372031 | 46 | { |
mikewebkist | 9:7ae675372031 | 47 | for(int z=0; z<w; z++) { |
mikewebkist | 9:7ae675372031 | 48 | if(x+z>=0 && x+z < 7) { |
mikewebkist | 9:7ae675372031 | 49 | LED[x+z]=1; |
mikewebkist | 9:7ae675372031 | 50 | } |
mikewebkist | 9:7ae675372031 | 51 | } |
mikewebkist | 9:7ae675372031 | 52 | wait(delayTime); |
mikewebkist | 9:7ae675372031 | 53 | for(int z=0; z<w; z++) { |
mikewebkist | 9:7ae675372031 | 54 | if(x+z>=0 && x+z < 7) { |
mikewebkist | 9:7ae675372031 | 55 | LED[x+z]=0; |
mikewebkist | 9:7ae675372031 | 56 | } |
mikewebkist | 9:7ae675372031 | 57 | } |
mikewebkist | 9:7ae675372031 | 58 | |
mikewebkist | 9:7ae675372031 | 59 | } |
mikewebkist | 9:7ae675372031 | 60 | } |
mikewebkist | 9:7ae675372031 | 61 | } |
mikewebkist | 9:7ae675372031 | 62 | |
mikewebkist | 7:c9e707fc8aa3 | 63 | void pileMode(float delayTime) |
mikewebkist | 7:c9e707fc8aa3 | 64 | { |
mikewebkist | 7:c9e707fc8aa3 | 65 | for(int x=0; x<7; x++) |
mikewebkist | 7:c9e707fc8aa3 | 66 | { |
mikewebkist | 7:c9e707fc8aa3 | 67 | for(int y=0; y<(6-x); y++) { |
mikewebkist | 7:c9e707fc8aa3 | 68 | LED[y]=1; |
mikewebkist | 7:c9e707fc8aa3 | 69 | wait(delayTime); |
mikewebkist | 7:c9e707fc8aa3 | 70 | LED[y]=0; |
mikewebkist | 7:c9e707fc8aa3 | 71 | } |
mikewebkist | 7:c9e707fc8aa3 | 72 | LED[6-x]=1; |
mikewebkist | 7:c9e707fc8aa3 | 73 | } |
mikewebkist | 8:41a5757f3bb9 | 74 | wait(delayTime); |
mikewebkist | 7:c9e707fc8aa3 | 75 | for(int x=0; x<7; x++) |
mikewebkist | 7:c9e707fc8aa3 | 76 | { |
mikewebkist | 7:c9e707fc8aa3 | 77 | LED[x] = 0; |
mikewebkist | 7:c9e707fc8aa3 | 78 | } |
mikewebkist | 7:c9e707fc8aa3 | 79 | } |
mikewebkist | 7:c9e707fc8aa3 | 80 | |
mikewebkist | 5:48b81f5fd186 | 81 | void randomMode(float delayTime) |
mikewebkist | 4:eea1a71b9a11 | 82 | { |
mikewebkist | 5:48b81f5fd186 | 83 | for(int x=0; x<128; x++) { |
mikewebkist | 5:48b81f5fd186 | 84 | rndLED = (int) RNG.getByte() % 8; |
mikewebkist | 5:48b81f5fd186 | 85 | LED[rndLED]=1; |
mikewebkist | 6:fe79549495e0 | 86 | wait(0.01); |
mikewebkist | 6:fe79549495e0 | 87 | LED[rndLED]=0; |
mikewebkist | 5:48b81f5fd186 | 88 | wait(delayTime); |
mikewebkist | 5:48b81f5fd186 | 89 | } |
mikewebkist | 5:48b81f5fd186 | 90 | } |
mikewebkist | 5:48b81f5fd186 | 91 | |
mikewebkist | 5:48b81f5fd186 | 92 | void binaryMode(float delayTime) { |
mikewebkist | 3:f3e484ae4439 | 93 | for(int n=0; n<128; n++) { |
mikewebkist | 3:f3e484ae4439 | 94 | for(int b=0; b<7; b++) { |
mikewebkist | 3:f3e484ae4439 | 95 | if(n & (1 << b)) { |
mikewebkist | 3:f3e484ae4439 | 96 | LED[6 - b]=1; |
mikewebkist | 3:f3e484ae4439 | 97 | } |
mikewebkist | 3:f3e484ae4439 | 98 | } |
mikewebkist | 5:48b81f5fd186 | 99 | wait(delayTime); |
mikewebkist | 3:f3e484ae4439 | 100 | for(int b=0; b<7; b++) { |
mikewebkist | 3:f3e484ae4439 | 101 | LED[b]=0; |
mikewebkist | 3:f3e484ae4439 | 102 | } |
mikewebkist | 3:f3e484ae4439 | 103 | } |
mikewebkist | 5:48b81f5fd186 | 104 | } |
mikewebkist | 5:48b81f5fd186 | 105 | |
mikewebkist | 5:48b81f5fd186 | 106 | void grayMode(float delayTime) { |
mikewebkist | 7:c9e707fc8aa3 | 107 | for(int b=0; b<7; b++) { LED[b]=0; } |
mikewebkist | 7:c9e707fc8aa3 | 108 | |
mikewebkist | 7:c9e707fc8aa3 | 109 | int prev=0; |
mikewebkist | 7:c9e707fc8aa3 | 110 | for(int n=1; n<128; n++) { |
mikewebkist | 7:c9e707fc8aa3 | 111 | int prevGray = (prev >> 1) ^ prev; |
mikewebkist | 4:eea1a71b9a11 | 112 | int gray = (n >> 1) ^ n; |
mikewebkist | 7:c9e707fc8aa3 | 113 | int diffBit = prevGray ^ gray; |
mikewebkist | 4:eea1a71b9a11 | 114 | for(int b=0; b<7; b++) { |
mikewebkist | 7:c9e707fc8aa3 | 115 | if(diffBit & (1 << b)) { |
mikewebkist | 7:c9e707fc8aa3 | 116 | LED[6 - b] = (diffBit & prevGray) ? 0 : 1; |
mikewebkist | 7:c9e707fc8aa3 | 117 | break; |
mikewebkist | 4:eea1a71b9a11 | 118 | } |
mikewebkist | 4:eea1a71b9a11 | 119 | } |
mikewebkist | 7:c9e707fc8aa3 | 120 | prev = n; |
mikewebkist | 5:48b81f5fd186 | 121 | wait(delayTime); |
mikewebkist | 4:eea1a71b9a11 | 122 | } |
mikewebkist | 5:48b81f5fd186 | 123 | } |
mikewebkist | 5:48b81f5fd186 | 124 | |
mikewebkist | 5:48b81f5fd186 | 125 | int main() |
mikewebkist | 5:48b81f5fd186 | 126 | { |
mikewebkist | 5:48b81f5fd186 | 127 | while(1) |
mikewebkist | 5:48b81f5fd186 | 128 | { |
mikewebkist | 5:48b81f5fd186 | 129 | sweep(0.05); |
mikewebkist | 5:48b81f5fd186 | 130 | binaryMode(0.05); |
mikewebkist | 5:48b81f5fd186 | 131 | sweep(0.05); |
mikewebkist | 7:c9e707fc8aa3 | 132 | randomMode(0.05); |
mikewebkist | 5:48b81f5fd186 | 133 | sweep(0.05); |
mikewebkist | 5:48b81f5fd186 | 134 | grayMode(0.05); |
mikewebkist | 6:fe79549495e0 | 135 | sweep(0.05); |
mikewebkist | 7:c9e707fc8aa3 | 136 | bounceMode(0.05); |
mikewebkist | 7:c9e707fc8aa3 | 137 | sweep(0.05); |
mikewebkist | 7:c9e707fc8aa3 | 138 | pileMode(0.05); |
mikewebkist | 9:7ae675372031 | 139 | sweep(0.05); |
mikewebkist | 9:7ae675372031 | 140 | multiSweepMode(0.05); |
Experiment626 | 0:aa0e1ad88af5 | 141 | } |
Experiment626 | 0:aa0e1ad88af5 | 142 | } |