Custom Hello World

Dependencies:   mbed

Fork of HelloWorld by Simon Ford

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut l1(LED1);
00004 DigitalOut l2(LED2);
00005 DigitalOut l3(LED3);
00006 DigitalOut l4(LED4);
00007 DigitalOut cs(p8);
00008 
00009 Serial pc(USBTX, USBRX);
00010 Serial uart(p9, p10);
00011 SPI spi(p5, p6, p7);
00012 I2C i2c(p28, p27);
00013 
00014 void lab_uart();
00015 void lab_spi();
00016 void lab_i2c();
00017 
00018 int main() {
00019     
00020     lab_i2c();
00021 }
00022 
00023 void lab_spi()
00024 {
00025     l2 = 1;
00026     pc.printf("Echoes back to the screen anything you type\n");
00027     
00028     while(1) {
00029         cs = 1;
00030         int input = pc.getc();
00031         cs = 0;
00032         spi.write(input);
00033         cs = 1;
00034     }
00035 }
00036 
00037 void lab_uart()
00038 {
00039     l1 = 1;
00040     pc.printf("Echoes back to the screen anything you type\n");
00041     
00042     while(1) {
00043         int input = pc.getc();
00044         uart.putc(input);
00045         if(pc.putc(input) == 4)
00046             l1 = l2 = l3 = l4 = 1;
00047         else
00048             l1 = l2 = l3 = l4 = 0;
00049     }
00050 }
00051 
00052 void lab_i2c()
00053 {
00054     pc.printf("i2c\n");
00055     
00056     //while(1) {
00057     //    int address = 0x01;
00058     //    char data[8];
00059     //    i2c.start();
00060     //    i2c.read(address, data, 8);
00061     //    for(int i = 0; i < 8; i++)
00062     //    {
00063     //        pc.putc(data[i]);
00064     //    }
00065     //    i2c.stop();
00066     //    wait(0.2);
00067     //}
00068     
00069     while(1)
00070     {
00071         i2c.start();
00072         i2c.write(0x1D);
00073         i2c.write(0x06);
00074         i2c.start();
00075         i2c.write(0x1D);
00076         int c=i2c.read(0);
00077         i2c.stop();
00078         //pc.putc(c);
00079         spi.write(c);
00080         wait(0.25);
00081     }
00082     
00083     
00084 }