two pin input

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI GYRO_DISCO_F429ZI

Committer:
t3421
Date:
Thu Dec 06 20:48:47 2018 +0000
Revision:
1:bbb4f79100de
Parent:
0:2f53fa259fef
fixed some comments;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
t3421 0:2f53fa259fef 1 #include "mbed.h"
t3421 0:2f53fa259fef 2 #include "LCD_DISCO_F429ZI.h"
t3421 0:2f53fa259fef 3 #include <string>
t3421 0:2f53fa259fef 4
t3421 0:2f53fa259fef 5 LCD_DISCO_F429ZI lcd;
t3421 0:2f53fa259fef 6 AnalogIn analog_value(PA_0); //Using pin PA0 for analog input
t3421 0:2f53fa259fef 7 AnalogIn analog_value1(PA_1);
t3421 0:2f53fa259fef 8 DigitalOut led(LED1); //Making the LED on if below 1V
t3421 0:2f53fa259fef 9
t3421 0:2f53fa259fef 10 extern void start_lcd();
t3421 0:2f53fa259fef 11 extern void draw_grid();
t3421 0:2f53fa259fef 12 extern void draw_sin(float, int, int);
t3421 0:2f53fa259fef 13
t3421 0:2f53fa259fef 14
t3421 0:2f53fa259fef 15 int main()
t3421 0:2f53fa259fef 16 {
t3421 0:2f53fa259fef 17 start_lcd();
t3421 0:2f53fa259fef 18 float meas_r, meas_v, meas_r1, meas_v1;
t3421 0:2f53fa259fef 19 int clock_timer = 0;
t3421 0:2f53fa259fef 20 while(1)
t3421 0:2f53fa259fef 21 {
t3421 0:2f53fa259fef 22 meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
t3421 0:2f53fa259fef 23 meas_v = meas_r * 2.92; // Converts value in the 0V-3.3V range
t3421 0:2f53fa259fef 24 meas_r1 = analog_value1.read();
t3421 0:2f53fa259fef 25 meas_v1 = meas_r1 * 2.92;
t3421 0:2f53fa259fef 26
t3421 0:2f53fa259fef 27 char output_number[16];
t3421 0:2f53fa259fef 28 char output_number1[16];
t3421 0:2f53fa259fef 29 sprintf( output_number, "In 1 : %.2f V", meas_v);
t3421 0:2f53fa259fef 30 sprintf( output_number1, "In 2 : %.2f V", meas_v1);
t3421 0:2f53fa259fef 31 lcd.DisplayStringAt(0, LINE(0), (uint8_t *) output_number , CENTER_MODE);
t3421 0:2f53fa259fef 32 lcd.DisplayStringAt(0, LINE(1), (uint8_t *) output_number1 , CENTER_MODE);
t3421 0:2f53fa259fef 33
t3421 0:2f53fa259fef 34 draw_sin(meas_v, clock_timer, 0);
t3421 0:2f53fa259fef 35 draw_sin(meas_v1, clock_timer, 1);
t3421 0:2f53fa259fef 36
t3421 0:2f53fa259fef 37 if (meas_v < 1)
t3421 0:2f53fa259fef 38 led = 1; // LED ON
t3421 0:2f53fa259fef 39
t3421 0:2f53fa259fef 40 else
t3421 0:2f53fa259fef 41 led = 0; // LED OFF
t3421 0:2f53fa259fef 42
t3421 0:2f53fa259fef 43 if (clock_timer == 240)
t3421 0:2f53fa259fef 44 {
t3421 0:2f53fa259fef 45 clock_timer = 0;
t3421 0:2f53fa259fef 46 lcd.Clear(LCD_COLOR_WHITE);;
t3421 0:2f53fa259fef 47 draw_grid();
t3421 0:2f53fa259fef 48 }
t3421 0:2f53fa259fef 49 else
t3421 0:2f53fa259fef 50 clock_timer++;
t3421 0:2f53fa259fef 51
t3421 0:2f53fa259fef 52 // wait(0.1); // 10th of a second
t3421 0:2f53fa259fef 53 }
t3421 0:2f53fa259fef 54 }
t3421 0:2f53fa259fef 55
t3421 0:2f53fa259fef 56 void start_lcd()
t3421 0:2f53fa259fef 57 {
t3421 0:2f53fa259fef 58 lcd.Clear(LCD_COLOR_BLUE);
t3421 0:2f53fa259fef 59 lcd.SetBackColor(LCD_COLOR_BLUE);
t3421 0:2f53fa259fef 60 lcd.SetTextColor(LCD_COLOR_WHITE);
t3421 0:2f53fa259fef 61 wait(0.3);
t3421 0:2f53fa259fef 62 lcd.DisplayStringAt(0, LINE(4), (uint8_t *)"DISCOVERY BOARD", CENTER_MODE);
t3421 1:bbb4f79100de 63 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"STM32F429", CENTER_MODE);
t3421 0:2f53fa259fef 64 lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"By: Teddy Sosnowski", CENTER_MODE);
t3421 0:2f53fa259fef 65 wait(1);
t3421 0:2f53fa259fef 66 lcd.Clear(LCD_COLOR_WHITE);
t3421 0:2f53fa259fef 67 BSP_LCD_SetFont(&Font16);
t3421 0:2f53fa259fef 68 draw_grid();
t3421 0:2f53fa259fef 69 lcd.SetTextColor(LCD_COLOR_WHITE);
t3421 0:2f53fa259fef 70 lcd.SetBackColor(LCD_COLOR_BLACK);
t3421 0:2f53fa259fef 71 }
t3421 0:2f53fa259fef 72 void draw_sin(float location, int x_axis, int input_number)
t3421 0:2f53fa259fef 73 {
t3421 1:bbb4f79100de 74 int y_axis = location * 24;
t3421 0:2f53fa259fef 75 y_axis = 180 - y_axis;
t3421 1:bbb4f79100de 76 //Center at pixel 120x180 for grid
t3421 0:2f53fa259fef 77 if (input_number == 0)
t3421 0:2f53fa259fef 78 BSP_LCD_DrawPixel(x_axis, y_axis, LCD_COLOR_RED);
t3421 0:2f53fa259fef 79 else
t3421 0:2f53fa259fef 80 BSP_LCD_DrawPixel(x_axis, y_axis, LCD_COLOR_GREEN);
t3421 0:2f53fa259fef 81 }
t3421 0:2f53fa259fef 82
t3421 0:2f53fa259fef 83 void draw_grid()
t3421 0:2f53fa259fef 84 {
t3421 0:2f53fa259fef 85 lcd.SetTextColor(LCD_COLOR_BLACK);
t3421 0:2f53fa259fef 86 lcd.SetBackColor(LCD_COLOR_WHITE);
t3421 0:2f53fa259fef 87 BSP_LCD_DrawHLine(0, 180, 240); //240X320 screen size
t3421 0:2f53fa259fef 88 BSP_LCD_DrawVLine(2, 98, 164);
t3421 0:2f53fa259fef 89 BSP_LCD_DisplayChar(5, 85 , 'V');
t3421 0:2f53fa259fef 90 BSP_LCD_DisplayChar(225, 160, 'T');
t3421 0:2f53fa259fef 91 lcd.SetTextColor(LCD_COLOR_GRAY);
t3421 0:2f53fa259fef 92
t3421 0:2f53fa259fef 93 BSP_LCD_DrawHLine(0, 156, 36);
t3421 0:2f53fa259fef 94 BSP_LCD_DrawHLine(0, 132, 36);
t3421 0:2f53fa259fef 95 BSP_LCD_DrawHLine(0, 108, 36);
t3421 0:2f53fa259fef 96 BSP_LCD_DrawHLine(0, 204, 36);
t3421 0:2f53fa259fef 97 BSP_LCD_DrawHLine(0, 228, 36);
t3421 0:2f53fa259fef 98 BSP_LCD_DrawHLine(0, 252, 36);
t3421 0:2f53fa259fef 99
t3421 0:2f53fa259fef 100 BSP_LCD_DrawVLine(20, 177, 6);
t3421 0:2f53fa259fef 101 BSP_LCD_DrawVLine(40, 177, 6);
t3421 0:2f53fa259fef 102 BSP_LCD_DrawVLine(60, 177, 6);
t3421 0:2f53fa259fef 103 BSP_LCD_DrawVLine(80, 177, 6);
t3421 0:2f53fa259fef 104 BSP_LCD_DrawVLine(100, 177, 6);
t3421 0:2f53fa259fef 105 BSP_LCD_DrawVLine(120, 177, 6);
t3421 0:2f53fa259fef 106 BSP_LCD_DrawVLine(140, 177, 6);
t3421 0:2f53fa259fef 107 BSP_LCD_DrawVLine(160, 177, 6);
t3421 0:2f53fa259fef 108 BSP_LCD_DrawVLine(180, 177, 6);
t3421 0:2f53fa259fef 109 BSP_LCD_DrawVLine(200, 177, 6);
t3421 0:2f53fa259fef 110 BSP_LCD_DrawVLine(220, 177, 6);
t3421 0:2f53fa259fef 111 lcd.SetTextColor(LCD_COLOR_WHITE);
t3421 0:2f53fa259fef 112 lcd.SetBackColor(LCD_COLOR_BLACK);
t3421 0:2f53fa259fef 113 }