c

Dependencies:   mbed Grove_LCD_RGB_Backlight

Committer:
dedsec
Date:
Sun Jul 11 03:07:08 2021 +0000
Revision:
2:e3219488a466
Parent:
1:734e32694486
n

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DavidRoss 0:cb2826e4b518 1 /*
DavidRoss 0:cb2826e4b518 2 Title: Program to position text on different coloured backgrounds.
DavidRoss 0:cb2826e4b518 3 Author: Dave Ross
DavidRoss 0:cb2826e4b518 4 Date: Mar 21st, 2019
DavidRoss 0:cb2826e4b518 5 Description: This program will take keyboard input to position
DavidRoss 0:cb2826e4b518 6 fixed text and to change the colour of screen the
DavidRoss 0:cb2826e4b518 7 text is displayed on.
DavidRoss 1:734e32694486 8 */
DavidRoss 0:cb2826e4b518 9 // Include Section
DavidRoss 0:cb2826e4b518 10 #include "Grove_LCD_RGB_Backlight.h" // Grove LCD header file
DavidRoss 0:cb2826e4b518 11 #include "mbed.h" // mbed header file
DavidRoss 0:cb2826e4b518 12
DavidRoss 0:cb2826e4b518 13 // Function Prototype Section
DavidRoss 0:cb2826e4b518 14 void clear(void); // clears the PC screen
DavidRoss 0:cb2826e4b518 15 void position(int x, int y); // positions screen cursor at (x,y)
DavidRoss 0:cb2826e4b518 16
DavidRoss 0:cb2826e4b518 17 // Hardware definition Section
DavidRoss 1:734e32694486 18 Grove_LCD_RGB_Backlight LCD(D14,D15); // lcd is associated with (D14,D15)
DavidRoss 0:cb2826e4b518 19 AnalogIn pot(A1); // pot is associated with A1
DavidRoss 1:734e32694486 20 const int MAX=20; // MAX is dimension of Buffer Array
DavidRoss 0:cb2826e4b518 21 int main(void)
DavidRoss 0:cb2826e4b518 22 {
DavidRoss 0:cb2826e4b518 23 char buffer[MAX]; // buffer has MAX elements
DavidRoss 1:734e32694486 24 double voltage,voltage1; // variable for storing voltage
DavidRoss 0:cb2826e4b518 25 int i; // variable used to null array
DavidRoss 0:cb2826e4b518 26 for(i=0;i<=MAX-1;++i) // NULL all elements 0 to MAX-1
DavidRoss 0:cb2826e4b518 27 {
DavidRoss 0:cb2826e4b518 28 buffer[i]=0; // set element to NULL character
DavidRoss 0:cb2826e4b518 29 }
DavidRoss 1:734e32694486 30 LCD.clear(); // clear lcd screen
DavidRoss 1:734e32694486 31 LCD.locate(0,0); // 1st column 1st row
DavidRoss 1:734e32694486 32 sprintf(buffer,"Reading Voltage");
DavidRoss 1:734e32694486 33 LCD.locate(1,0);
DavidRoss 1:734e32694486 34 LCD.print(buffer);
DavidRoss 1:734e32694486 35 LCD.setRGB(0x00,0x00,0xff); // set background to blue
DavidRoss 0:cb2826e4b518 36 for(;;) // infinite loop
DavidRoss 0:cb2826e4b518 37 {
DavidRoss 0:cb2826e4b518 38 voltage=pot.read(); // voltage reading (0-1) from pot
DavidRoss 1:734e32694486 39 voltage1=3.33*voltage; // scale to 3.33 volts
DavidRoss 1:734e32694486 40 LCD.locate(2,1); // 4th column 2nd row
DavidRoss 1:734e32694486 41 sprintf(buffer,"%5.3f %5.3f",
DavidRoss 1:734e32694486 42 voltage,voltage1); // voltage to string in buffer
DavidRoss 1:734e32694486 43 LCD.print(buffer); // print buffer on lcd
DavidRoss 0:cb2826e4b518 44 wait(0.05);
DavidRoss 0:cb2826e4b518 45 }
DavidRoss 0:cb2826e4b518 46 }