LCD16x2,gy25,using Serial.getc()

Dependencies:   MPU6050 TextLCD mbed

Committer:
iskenny4
Date:
Thu May 25 08:48:51 2017 +0000
Revision:
0:88e974ab5621
LCD displays gy25's angles(z,x,y) with .getc()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iskenny4 0:88e974ab5621 1 #include "mbed.h"
iskenny4 0:88e974ab5621 2 #include "TextLCD.h"
iskenny4 0:88e974ab5621 3
iskenny4 0:88e974ab5621 4 TextLCD lcd(PA_0,PA_1,PA_4,PB_0,PC_1,PC_0); // RS, E, D4-D7
iskenny4 0:88e974ab5621 5 Serial gy25(PA_9, PA_10, 115200);
iskenny4 0:88e974ab5621 6 DigitalOut rw(PA_8); // RW
iskenny4 0:88e974ab5621 7
iskenny4 0:88e974ab5621 8 int g[3];
iskenny4 0:88e974ab5621 9 char rxC[8];
iskenny4 0:88e974ab5621 10
iskenny4 0:88e974ab5621 11 void rxIRQ(){
iskenny4 0:88e974ab5621 12 rxC[0] = gy25.getc();
iskenny4 0:88e974ab5621 13 if (rxC[0] == 170) {
iskenny4 0:88e974ab5621 14 for (int i = 1; i < 8; i++) {
iskenny4 0:88e974ab5621 15 rxC[i] = gy25.getc();
iskenny4 0:88e974ab5621 16 }
iskenny4 0:88e974ab5621 17 if (rxC[7] == 85) {
iskenny4 0:88e974ab5621 18 for (int i = 0, j =1; i < 3; i++, j+=2) {
iskenny4 0:88e974ab5621 19 g[i] = (rxC[j]<<8 | rxC[j+1])/100;
iskenny4 0:88e974ab5621 20 if (g[i] > 475)
iskenny4 0:88e974ab5621 21 g[i] = g[i] - 476 + 180;
iskenny4 0:88e974ab5621 22 }
iskenny4 0:88e974ab5621 23 }
iskenny4 0:88e974ab5621 24 }
iskenny4 0:88e974ab5621 25 }
iskenny4 0:88e974ab5621 26
iskenny4 0:88e974ab5621 27 int main()
iskenny4 0:88e974ab5621 28 {
iskenny4 0:88e974ab5621 29 gy25.format(8,SerialBase::None,1);
iskenny4 0:88e974ab5621 30 lcd.cls();
iskenny4 0:88e974ab5621 31 lcd.printf("LCD work");
iskenny4 0:88e974ab5621 32 wait(1);
iskenny4 0:88e974ab5621 33 gy25.attach(rxIRQ, RawSerial::RxIrq);
iskenny4 0:88e974ab5621 34 while(1) {
iskenny4 0:88e974ab5621 35 lcd.locate(0,1);
iskenny4 0:88e974ab5621 36 lcd.printf("%d,%d,%d",g[0],g[1],g[2]);
iskenny4 0:88e974ab5621 37 wait(0.4);
iskenny4 0:88e974ab5621 38 lcd.cls();
iskenny4 0:88e974ab5621 39 }
iskenny4 0:88e974ab5621 40 }