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 Aron Phillips

mBuino blinky experiments.

Committer:
mikewebkist
Date:
Tue Sep 09 12:44:18 2014 +0000
Revision:
13:292326e5d3bb
Parent:
12:c94348aca325
Child:
14:cdc203a0bdc1
change wakeup timeout

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Experiment626 0:aa0e1ad88af5 1 #include "mbed.h"
mikewebkist 2:fd6008aa85cd 2 #include "RNG/Random.h"
mikewebkist 11:be76674d2dbd 3 #include "WakeUp/WakeUp.h"
Experiment626 0:aa0e1ad88af5 4
Experiment626 0:aa0e1ad88af5 5 DigitalOut LED[] = {(P0_7), (P0_8), (P0_2), (P0_20), (P1_19), (P0_17), (P0_23)};// declare 7 LEDs
Experiment626 0:aa0e1ad88af5 6
mikewebkist 2:fd6008aa85cd 7 int rndLED = 0;
mikewebkist 2:fd6008aa85cd 8 Random RNG = Random();
Experiment626 0:aa0e1ad88af5 9
mikewebkist 10:8a901b6d8cfa 10 void myDeepSleep() {
mikewebkist 10:8a901b6d8cfa 11 LPC_PMU->PCON = 0x1;
mikewebkist 10:8a901b6d8cfa 12 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
mikewebkist 10:8a901b6d8cfa 13 LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800;
mikewebkist 10:8a901b6d8cfa 14 __WFI();
mikewebkist 10:8a901b6d8cfa 15 }
mikewebkist 10:8a901b6d8cfa 16
mikewebkist 12:c94348aca325 17 void sweepMode(float delayTime)
Experiment626 0:aa0e1ad88af5 18 {
mikewebkist 1:47c61bf9c81e 19 for(int x=0; x<7; x++)
Experiment626 0:aa0e1ad88af5 20 {
mikewebkist 1:47c61bf9c81e 21 LED[x] = 1;
mikewebkist 1:47c61bf9c81e 22 wait(delayTime);
Experiment626 0:aa0e1ad88af5 23 }
mikewebkist 2:fd6008aa85cd 24
mikewebkist 2:fd6008aa85cd 25 for(int x=6; x>=0; x--)
Experiment626 0:aa0e1ad88af5 26 {
mikewebkist 2:fd6008aa85cd 27 LED[x] = 0;
mikewebkist 1:47c61bf9c81e 28 wait(delayTime);
Experiment626 0:aa0e1ad88af5 29 }
mikewebkist 4:eea1a71b9a11 30 }
mikewebkist 4:eea1a71b9a11 31
mikewebkist 6:fe79549495e0 32 void bounceMode(float delayTime)
mikewebkist 6:fe79549495e0 33 {
mikewebkist 6:fe79549495e0 34 for(int x=0; x<7; x++)
mikewebkist 6:fe79549495e0 35 {
mikewebkist 6:fe79549495e0 36 LED[x] = 1;
mikewebkist 6:fe79549495e0 37 wait(delayTime);
mikewebkist 6:fe79549495e0 38 LED[x] = 0;
mikewebkist 6:fe79549495e0 39 }
mikewebkist 6:fe79549495e0 40
mikewebkist 6:fe79549495e0 41 for(int x=6; x>=0; x--)
mikewebkist 6:fe79549495e0 42 {
mikewebkist 6:fe79549495e0 43 LED[x] = 1;
mikewebkist 6:fe79549495e0 44 wait(delayTime);
mikewebkist 6:fe79549495e0 45 LED[x] = 0;
mikewebkist 6:fe79549495e0 46 }
mikewebkist 6:fe79549495e0 47 }
mikewebkist 6:fe79549495e0 48
mikewebkist 9:7ae675372031 49 void multiSweepMode(float delayTime)
mikewebkist 9:7ae675372031 50 {
mikewebkist 9:7ae675372031 51 for(int w=1; w<13; w++)
mikewebkist 9:7ae675372031 52 {
mikewebkist 9:7ae675372031 53 for(int x=1-w; x<13; x++)
mikewebkist 9:7ae675372031 54 {
mikewebkist 9:7ae675372031 55 for(int z=0; z<w; z++) {
mikewebkist 9:7ae675372031 56 if(x+z>=0 && x+z < 7) {
mikewebkist 9:7ae675372031 57 LED[x+z]=1;
mikewebkist 9:7ae675372031 58 }
mikewebkist 9:7ae675372031 59 }
mikewebkist 9:7ae675372031 60 wait(delayTime);
mikewebkist 9:7ae675372031 61 for(int z=0; z<w; z++) {
mikewebkist 9:7ae675372031 62 if(x+z>=0 && x+z < 7) {
mikewebkist 9:7ae675372031 63 LED[x+z]=0;
mikewebkist 9:7ae675372031 64 }
mikewebkist 9:7ae675372031 65 }
mikewebkist 9:7ae675372031 66
mikewebkist 9:7ae675372031 67 }
mikewebkist 9:7ae675372031 68 }
mikewebkist 9:7ae675372031 69 }
mikewebkist 9:7ae675372031 70
mikewebkist 7:c9e707fc8aa3 71 void pileMode(float delayTime)
mikewebkist 7:c9e707fc8aa3 72 {
mikewebkist 7:c9e707fc8aa3 73 for(int x=0; x<7; x++)
mikewebkist 7:c9e707fc8aa3 74 {
mikewebkist 7:c9e707fc8aa3 75 for(int y=0; y<(6-x); y++) {
mikewebkist 7:c9e707fc8aa3 76 LED[y]=1;
mikewebkist 7:c9e707fc8aa3 77 wait(delayTime);
mikewebkist 7:c9e707fc8aa3 78 LED[y]=0;
mikewebkist 7:c9e707fc8aa3 79 }
mikewebkist 7:c9e707fc8aa3 80 LED[6-x]=1;
mikewebkist 7:c9e707fc8aa3 81 }
mikewebkist 8:41a5757f3bb9 82 wait(delayTime);
mikewebkist 7:c9e707fc8aa3 83 for(int x=0; x<7; x++)
mikewebkist 7:c9e707fc8aa3 84 {
mikewebkist 7:c9e707fc8aa3 85 LED[x] = 0;
mikewebkist 7:c9e707fc8aa3 86 }
mikewebkist 7:c9e707fc8aa3 87 }
mikewebkist 7:c9e707fc8aa3 88
mikewebkist 5:48b81f5fd186 89 void randomMode(float delayTime)
mikewebkist 4:eea1a71b9a11 90 {
mikewebkist 5:48b81f5fd186 91 for(int x=0; x<128; x++) {
mikewebkist 5:48b81f5fd186 92 rndLED = (int) RNG.getByte() % 8;
mikewebkist 5:48b81f5fd186 93 LED[rndLED]=1;
mikewebkist 6:fe79549495e0 94 wait(0.01);
mikewebkist 6:fe79549495e0 95 LED[rndLED]=0;
mikewebkist 5:48b81f5fd186 96 wait(delayTime);
mikewebkist 5:48b81f5fd186 97 }
mikewebkist 5:48b81f5fd186 98 }
mikewebkist 5:48b81f5fd186 99
mikewebkist 5:48b81f5fd186 100 void binaryMode(float delayTime) {
mikewebkist 3:f3e484ae4439 101 for(int n=0; n<128; n++) {
mikewebkist 3:f3e484ae4439 102 for(int b=0; b<7; b++) {
mikewebkist 3:f3e484ae4439 103 if(n & (1 << b)) {
mikewebkist 3:f3e484ae4439 104 LED[6 - b]=1;
mikewebkist 3:f3e484ae4439 105 }
mikewebkist 3:f3e484ae4439 106 }
mikewebkist 5:48b81f5fd186 107 wait(delayTime);
mikewebkist 3:f3e484ae4439 108 for(int b=0; b<7; b++) {
mikewebkist 3:f3e484ae4439 109 LED[b]=0;
mikewebkist 3:f3e484ae4439 110 }
mikewebkist 3:f3e484ae4439 111 }
mikewebkist 5:48b81f5fd186 112 }
mikewebkist 5:48b81f5fd186 113
mikewebkist 5:48b81f5fd186 114 void grayMode(float delayTime) {
mikewebkist 7:c9e707fc8aa3 115 for(int b=0; b<7; b++) { LED[b]=0; }
mikewebkist 7:c9e707fc8aa3 116
mikewebkist 7:c9e707fc8aa3 117 int prev=0;
mikewebkist 7:c9e707fc8aa3 118 for(int n=1; n<128; n++) {
mikewebkist 7:c9e707fc8aa3 119 int prevGray = (prev >> 1) ^ prev;
mikewebkist 4:eea1a71b9a11 120 int gray = (n >> 1) ^ n;
mikewebkist 7:c9e707fc8aa3 121 int diffBit = prevGray ^ gray;
mikewebkist 4:eea1a71b9a11 122 for(int b=0; b<7; b++) {
mikewebkist 7:c9e707fc8aa3 123 if(diffBit & (1 << b)) {
mikewebkist 7:c9e707fc8aa3 124 LED[6 - b] = (diffBit & prevGray) ? 0 : 1;
mikewebkist 7:c9e707fc8aa3 125 break;
mikewebkist 4:eea1a71b9a11 126 }
mikewebkist 4:eea1a71b9a11 127 }
mikewebkist 7:c9e707fc8aa3 128 prev = n;
mikewebkist 5:48b81f5fd186 129 wait(delayTime);
mikewebkist 4:eea1a71b9a11 130 }
mikewebkist 5:48b81f5fd186 131 }
mikewebkist 5:48b81f5fd186 132
mikewebkist 12:c94348aca325 133 void bumpMode(float delayTime) {
mikewebkist 12:c94348aca325 134 for(int x=0; x<3; x++) {
mikewebkist 12:c94348aca325 135 LED[x]=1;
mikewebkist 12:c94348aca325 136 LED[6-x]=1;
mikewebkist 12:c94348aca325 137 wait(delayTime * 2);
mikewebkist 12:c94348aca325 138 LED[x]=0;
mikewebkist 12:c94348aca325 139 LED[6-x]=0;
mikewebkist 12:c94348aca325 140 }
mikewebkist 12:c94348aca325 141 LED[3]=1;
mikewebkist 12:c94348aca325 142 wait(delayTime * 2);
mikewebkist 12:c94348aca325 143 LED[3]=0;
mikewebkist 12:c94348aca325 144 for(int x=0; x<3; x++) {
mikewebkist 12:c94348aca325 145 LED[2-x]=1;
mikewebkist 12:c94348aca325 146 LED[4+x]=1;
mikewebkist 12:c94348aca325 147 wait(delayTime * 2);
mikewebkist 12:c94348aca325 148 LED[2-x]=0;
mikewebkist 12:c94348aca325 149 LED[4+x]=0;
mikewebkist 12:c94348aca325 150 }
mikewebkist 12:c94348aca325 151 wait(delayTime * 4);
mikewebkist 12:c94348aca325 152 }
mikewebkist 12:c94348aca325 153
mikewebkist 5:48b81f5fd186 154 int main()
mikewebkist 5:48b81f5fd186 155 {
mikewebkist 5:48b81f5fd186 156 while(1)
mikewebkist 5:48b81f5fd186 157 {
mikewebkist 12:c94348aca325 158 bumpMode(0.05);
mikewebkist 12:c94348aca325 159 int x = (int) RNG.getByte() % 7;
mikewebkist 11:be76674d2dbd 160 switch(x) {
mikewebkist 11:be76674d2dbd 161 case 0:
mikewebkist 11:be76674d2dbd 162 binaryMode(0.05);
mikewebkist 11:be76674d2dbd 163 break;
mikewebkist 11:be76674d2dbd 164 case 1:
mikewebkist 11:be76674d2dbd 165 randomMode(0.05);
mikewebkist 11:be76674d2dbd 166 break;
mikewebkist 11:be76674d2dbd 167 case 2:
mikewebkist 11:be76674d2dbd 168 grayMode(0.05);
mikewebkist 11:be76674d2dbd 169 break;
mikewebkist 11:be76674d2dbd 170 case 3:
mikewebkist 11:be76674d2dbd 171 bounceMode(0.05);
mikewebkist 11:be76674d2dbd 172 break;
mikewebkist 11:be76674d2dbd 173 case 4:
mikewebkist 11:be76674d2dbd 174 pileMode(0.05);
mikewebkist 11:be76674d2dbd 175 break;
mikewebkist 11:be76674d2dbd 176 case 5:
mikewebkist 11:be76674d2dbd 177 multiSweepMode(0.05);
mikewebkist 11:be76674d2dbd 178 break;
mikewebkist 12:c94348aca325 179 case 6:
mikewebkist 12:c94348aca325 180 sweepMode(0.05);
mikewebkist 12:c94348aca325 181 break;
mikewebkist 11:be76674d2dbd 182 }
mikewebkist 12:c94348aca325 183 bumpMode(0.05);
mikewebkist 13:292326e5d3bb 184 WakeUp::set(10);
mikewebkist 10:8a901b6d8cfa 185 myDeepSleep();
Experiment626 0:aa0e1ad88af5 186 }
Experiment626 0:aa0e1ad88af5 187 }