UART array transmission test code. (Receive)

Dependencies:   mbed

Committer:
el15tcd
Date:
Mon Feb 19 13:09:08 2018 +0000
Revision:
1:adb918553885
Parent:
0:c16e741bd863
Child:
2:6f9b37d8b6aa
Matrix Demonstration (2x2)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el15tcd 0:c16e741bd863 1 #include "mbed.h"
el15tcd 0:c16e741bd863 2
el15tcd 0:c16e741bd863 3 Serial device2(p9,p10); //tx,rx
el15tcd 0:c16e741bd863 4 BusOut myleds(LED4, LED3, LED2, LED1);
el15tcd 0:c16e741bd863 5
el15tcd 0:c16e741bd863 6 int buffer2[8];
el15tcd 0:c16e741bd863 7 int temp2;
el15tcd 0:c16e741bd863 8
el15tcd 1:adb918553885 9 char matrix2[2][2];
el15tcd 1:adb918553885 10
el15tcd 0:c16e741bd863 11 int led1;
el15tcd 0:c16e741bd863 12 int led2;
el15tcd 0:c16e741bd863 13 int led3;
el15tcd 0:c16e741bd863 14 int led4;
el15tcd 0:c16e741bd863 15
el15tcd 0:c16e741bd863 16 int main()
el15tcd 0:c16e741bd863 17 {
el15tcd 0:c16e741bd863 18
el15tcd 0:c16e741bd863 19 myleds = 0;
el15tcd 0:c16e741bd863 20
el15tcd 0:c16e741bd863 21 device2.baud(19200);
el15tcd 0:c16e741bd863 22
el15tcd 0:c16e741bd863 23 while(1) {
el15tcd 0:c16e741bd863 24 temp2 = device2.getc();
el15tcd 0:c16e741bd863 25 if (temp2 == 1) {
el15tcd 1:adb918553885 26 for (int i=0; i<2; i++) {
el15tcd 1:adb918553885 27 for (int j=0; j<2; j++) {
el15tcd 0:c16e741bd863 28
el15tcd 1:adb918553885 29 matrix2[i][j] = device2.getc();
el15tcd 1:adb918553885 30 temp2 = matrix2[i][j];
el15tcd 1:adb918553885 31 if ((temp2 == 1)&&(i == 0)&&(j == 0)) {
el15tcd 1:adb918553885 32 led1 = 1;
el15tcd 1:adb918553885 33 } else if ((i == 0)&&(j == 0)) {
el15tcd 1:adb918553885 34 led1 = 0;
el15tcd 1:adb918553885 35 }
el15tcd 1:adb918553885 36 if ((temp2 == 1)&&(i == 0)&&(j == 1)) {
el15tcd 1:adb918553885 37 led2 = 2;
el15tcd 1:adb918553885 38 } else if ((i == 0)&&(j == 1)) {
el15tcd 1:adb918553885 39 led2 = 0;
el15tcd 1:adb918553885 40 }
el15tcd 1:adb918553885 41 if ((temp2 == 1)&&(i == 1)&&(j == 0)) {
el15tcd 1:adb918553885 42 led3 = 4;
el15tcd 1:adb918553885 43 } else if ((i == 1)&&(j == 0)) {
el15tcd 1:adb918553885 44 led3 = 0;
el15tcd 1:adb918553885 45 }
el15tcd 1:adb918553885 46 if ((temp2 == 1)&&(i == 1)&&(j == 1)) {
el15tcd 1:adb918553885 47 led4 = 8;
el15tcd 1:adb918553885 48 } else if ((i == 1)&&(j == 1)) {
el15tcd 1:adb918553885 49 led4 = 0;
el15tcd 1:adb918553885 50 }
el15tcd 1:adb918553885 51
el15tcd 0:c16e741bd863 52 }
el15tcd 0:c16e741bd863 53 }
el15tcd 0:c16e741bd863 54 myleds = led1 + led2 + led3 + led4;
el15tcd 0:c16e741bd863 55 }
el15tcd 0:c16e741bd863 56 }
el15tcd 0:c16e741bd863 57
el15tcd 0:c16e741bd863 58 }