Custom Hello World

Dependencies:   mbed

Fork of HelloWorld by Simon Ford

Committer:
mikaelbro
Date:
Wed Aug 30 18:40:58 2017 +0000
Revision:
11:b77fd6ee58f8
Parent:
10:d1c3bc60f1eb
tout

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:fb6bbc10ffa0 1 #include "mbed.h"
simon 0:fb6bbc10ffa0 2
mikaelbro 2:efed707da03a 3 DigitalOut l1(LED1);
mikaelbro 2:efed707da03a 4 DigitalOut l2(LED2);
mikaelbro 2:efed707da03a 5 DigitalOut l3(LED3);
mikaelbro 2:efed707da03a 6 DigitalOut l4(LED4);
steeven233 10:d1c3bc60f1eb 7 DigitalOut cs(p8);
mikaelbro 11:b77fd6ee58f8 8
mikaelbro 7:1165c9f38b27 9 Serial pc(USBTX, USBRX);
mikaelbro 8:cb869f104caa 10 Serial uart(p9, p10);
mikaelbro 9:7009059be465 11 SPI spi(p5, p6, p7);
mikaelbro 11:b77fd6ee58f8 12 I2C i2c(p28, p27);
mikaelbro 9:7009059be465 13
mikaelbro 9:7009059be465 14 void lab_uart();
mikaelbro 9:7009059be465 15 void lab_spi();
mikaelbro 11:b77fd6ee58f8 16 void lab_i2c();
simon 0:fb6bbc10ffa0 17
simon 0:fb6bbc10ffa0 18 int main() {
mikaelbro 2:efed707da03a 19
mikaelbro 11:b77fd6ee58f8 20 lab_i2c();
mikaelbro 9:7009059be465 21 }
mikaelbro 9:7009059be465 22
mikaelbro 9:7009059be465 23 void lab_spi()
mikaelbro 9:7009059be465 24 {
mikaelbro 9:7009059be465 25 l2 = 1;
mikaelbro 9:7009059be465 26 pc.printf("Echoes back to the screen anything you type\n");
mikaelbro 9:7009059be465 27
mikaelbro 9:7009059be465 28 while(1) {
steeven233 10:d1c3bc60f1eb 29 cs = 1;
mikaelbro 9:7009059be465 30 int input = pc.getc();
steeven233 10:d1c3bc60f1eb 31 cs = 0;
mikaelbro 9:7009059be465 32 spi.write(input);
steeven233 10:d1c3bc60f1eb 33 cs = 1;
mikaelbro 9:7009059be465 34 }
mikaelbro 9:7009059be465 35 }
mikaelbro 9:7009059be465 36
mikaelbro 9:7009059be465 37 void lab_uart()
mikaelbro 9:7009059be465 38 {
mikaelbro 2:efed707da03a 39 l1 = 1;
mikaelbro 7:1165c9f38b27 40 pc.printf("Echoes back to the screen anything you type\n");
mikaelbro 9:7009059be465 41
simon 0:fb6bbc10ffa0 42 while(1) {
mikaelbro 9:7009059be465 43 int input = pc.getc();
mikaelbro 9:7009059be465 44 uart.putc(input);
mikaelbro 9:7009059be465 45 if(pc.putc(input) == 4)
mikaelbro 9:7009059be465 46 l1 = l2 = l3 = l4 = 1;
mikaelbro 9:7009059be465 47 else
mikaelbro 11:b77fd6ee58f8 48 l1 = l2 = l3 = l4 = 0;
simon 0:fb6bbc10ffa0 49 }
mikaelbro 11:b77fd6ee58f8 50 }
mikaelbro 11:b77fd6ee58f8 51
mikaelbro 11:b77fd6ee58f8 52 void lab_i2c()
mikaelbro 11:b77fd6ee58f8 53 {
mikaelbro 11:b77fd6ee58f8 54 pc.printf("i2c\n");
mikaelbro 11:b77fd6ee58f8 55
mikaelbro 11:b77fd6ee58f8 56 //while(1) {
mikaelbro 11:b77fd6ee58f8 57 // int address = 0x01;
mikaelbro 11:b77fd6ee58f8 58 // char data[8];
mikaelbro 11:b77fd6ee58f8 59 // i2c.start();
mikaelbro 11:b77fd6ee58f8 60 // i2c.read(address, data, 8);
mikaelbro 11:b77fd6ee58f8 61 // for(int i = 0; i < 8; i++)
mikaelbro 11:b77fd6ee58f8 62 // {
mikaelbro 11:b77fd6ee58f8 63 // pc.putc(data[i]);
mikaelbro 11:b77fd6ee58f8 64 // }
mikaelbro 11:b77fd6ee58f8 65 // i2c.stop();
mikaelbro 11:b77fd6ee58f8 66 // wait(0.2);
mikaelbro 11:b77fd6ee58f8 67 //}
mikaelbro 11:b77fd6ee58f8 68
mikaelbro 11:b77fd6ee58f8 69 while(1)
mikaelbro 11:b77fd6ee58f8 70 {
mikaelbro 11:b77fd6ee58f8 71 i2c.start();
mikaelbro 11:b77fd6ee58f8 72 i2c.write(0x1D);
mikaelbro 11:b77fd6ee58f8 73 i2c.write(0x06);
mikaelbro 11:b77fd6ee58f8 74 i2c.start();
mikaelbro 11:b77fd6ee58f8 75 i2c.write(0x1D);
mikaelbro 11:b77fd6ee58f8 76 int c=i2c.read(0);
mikaelbro 11:b77fd6ee58f8 77 i2c.stop();
mikaelbro 11:b77fd6ee58f8 78 //pc.putc(c);
mikaelbro 11:b77fd6ee58f8 79 spi.write(c);
mikaelbro 11:b77fd6ee58f8 80 wait(0.25);
mikaelbro 11:b77fd6ee58f8 81 }
mikaelbro 11:b77fd6ee58f8 82
mikaelbro 11:b77fd6ee58f8 83
mikaelbro 9:7009059be465 84 }