IoT 2018

Dependencies:   mbed

Fork of microbit_blinky by BBC

main.cpp

Committer:
f3d
Date:
2018-09-20
Revision:
1:0b38b848a5f0
Parent:
0:025387782f3e
Child:
2:83f7d8e01b11

File content as of revision 1:0b38b848a5f0:

#include "mbed.h"

// Button A is on P0 bit 17 
// Pin labelled "0" on edge connector is in fact connected to P0_3 
volatile uint32_t * P0OUT = (uint32_t *)0x50000504;
volatile uint32_t * P0DIR = (uint32_t *)0x50000514;
volatile uint32_t * P0IN  = (uint32_t *)0x50000510;
volatile uint32_t * P0CONF  = (uint32_t *)(0x50000700);

void dly(volatile uint32_t len)
{
    // "volatile" modifier is necessary here 
    // to prevent the compiler from optimizing 
    // this software delay to nothing
    while(len--);
}
int ButtonAPressed()
{
    // Button A pulls down so bit is zero when pressed.
    if ((*P0IN & (1 << 17))==0)    
        return 1;
    else
        return 0;
}
int main() {
    
    *P0DIR = (1 << 3);    
    P0CONF[17] = 0;  // On power up, input buffer is not connected so must do this
    while(1) {                 
        if (ButtonAPressed()) 
            *P0OUT = (1 << 3);       
        else
            *P0OUT = 0;                      
    }
}