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.

main.cpp

Committer:
mikewebkist
Date:
2014-09-05
Revision:
5:48b81f5fd186
Parent:
4:eea1a71b9a11
Child:
6:fe79549495e0

File content as of revision 5:48b81f5fd186:

#include "mbed.h"
#include "RNG/Random.h"

DigitalOut LED[] = {(P0_7), (P0_8), (P0_2), (P0_20), (P1_19), (P0_17), (P0_23)};// declare 7 LEDs

int rndLED = 0;
Random RNG = Random();

void sweep(float delayTime)
{
        for(int x=0; x<7; x++)
        {
            LED[x] = 1;
            wait(delayTime);
        }

        for(int x=6; x>=0; x--)
        {
            LED[x] = 0;
            wait(delayTime);
        }
}

void randomMode(float delayTime)
{
    for(int x=0; x<128; x++) {
        rndLED = (int) RNG.getByte() % 8;
        LED[rndLED]=1;
        wait(delayTime);
        LED[rndLED]=0;
    }
}

void binaryMode(float delayTime) {
        for(int n=0; n<128; n++) {
            for(int b=0; b<7; b++) {
                if(n & (1 << b)) {
                    LED[6 - b]=1;
                }
            }
            wait(delayTime);
            for(int b=0; b<7; b++) {
                LED[b]=0;
            }
        }
}

void grayMode(float delayTime) {
        for(int n=0; n<128; n++) {
            int gray = (n >> 1) ^ n;
            for(int b=0; b<7; b++) {
                if(gray & (1 << b)) {
                    LED[6 - b]=1;
                }
            }
            wait(delayTime);
            for(int b=0; b<7; b++) {
                LED[b]=0;
            }
        }
}

int main()
{
    while(1)
    {
        sweep(0.05);
        binaryMode(0.05);
        sweep(0.05);
        randomMode(0.025);
        sweep(0.05);
        grayMode(0.05);
    }
}