Custom Hello World

Dependencies:   mbed

Fork of HelloWorld by Simon Ford

main.cpp

Committer:
mikaelbro
Date:
2017-08-30
Revision:
11:b77fd6ee58f8
Parent:
10:d1c3bc60f1eb

File content as of revision 11:b77fd6ee58f8:

#include "mbed.h"

DigitalOut l1(LED1);
DigitalOut l2(LED2);
DigitalOut l3(LED3);
DigitalOut l4(LED4);
DigitalOut cs(p8);

Serial pc(USBTX, USBRX);
Serial uart(p9, p10);
SPI spi(p5, p6, p7);
I2C i2c(p28, p27);

void lab_uart();
void lab_spi();
void lab_i2c();

int main() {
    
    lab_i2c();
}

void lab_spi()
{
    l2 = 1;
    pc.printf("Echoes back to the screen anything you type\n");
    
    while(1) {
        cs = 1;
        int input = pc.getc();
        cs = 0;
        spi.write(input);
        cs = 1;
    }
}

void lab_uart()
{
    l1 = 1;
    pc.printf("Echoes back to the screen anything you type\n");
    
    while(1) {
        int input = pc.getc();
        uart.putc(input);
        if(pc.putc(input) == 4)
            l1 = l2 = l3 = l4 = 1;
        else
            l1 = l2 = l3 = l4 = 0;
    }
}

void lab_i2c()
{
    pc.printf("i2c\n");
    
    //while(1) {
    //    int address = 0x01;
    //    char data[8];
    //    i2c.start();
    //    i2c.read(address, data, 8);
    //    for(int i = 0; i < 8; i++)
    //    {
    //        pc.putc(data[i]);
    //    }
    //    i2c.stop();
    //    wait(0.2);
    //}
    
    while(1)
    {
        i2c.start();
        i2c.write(0x1D);
        i2c.write(0x06);
        i2c.start();
        i2c.write(0x1D);
        int c=i2c.read(0);
        i2c.stop();
        //pc.putc(c);
        spi.write(c);
        wait(0.25);
    }
    
    
}