c

Dependencies:   mbed Grove_LCD_RGB_Backlight

Committer:
DavidRoss
Date:
Thu Aug 27 17:22:29 2020 +0000
Revision:
0:cb2826e4b518
Child:
1:734e32694486
good version

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 0:cb2826e4b518 8 */
DavidRoss 0:cb2826e4b518 9
DavidRoss 0:cb2826e4b518 10 // Include Section
DavidRoss 0:cb2826e4b518 11 #include "Grove_LCD_RGB_Backlight.h" // Grove LCD header file
DavidRoss 0:cb2826e4b518 12 #include "mbed.h" // mbed header file
DavidRoss 0:cb2826e4b518 13
DavidRoss 0:cb2826e4b518 14 // Function Prototype Section
DavidRoss 0:cb2826e4b518 15 void clear(void); // clears the PC screen
DavidRoss 0:cb2826e4b518 16 void position(int x, int y); // positions screen cursor at (x,y)
DavidRoss 0:cb2826e4b518 17
DavidRoss 0:cb2826e4b518 18 // Hardware definition Section
DavidRoss 0:cb2826e4b518 19 Grove_LCD_RGB_Backlight lcd(D14,D15); // lcd is associated with (D14,D15)
DavidRoss 0:cb2826e4b518 20 AnalogIn pot(A1); // pot is associated with A1
DavidRoss 0:cb2826e4b518 21 const int MAX=10; // MAX is dimension of Buffer Array
DavidRoss 0:cb2826e4b518 22 int main(void)
DavidRoss 0:cb2826e4b518 23 {
DavidRoss 0:cb2826e4b518 24 char buffer[MAX]; // buffer has MAX elements
DavidRoss 0:cb2826e4b518 25 double voltage; // variable for storing voltage
DavidRoss 0:cb2826e4b518 26 int i; // variable used to null array
DavidRoss 0:cb2826e4b518 27 for(i=0;i<=MAX-1;++i) // NULL all elements 0 to MAX-1
DavidRoss 0:cb2826e4b518 28 {
DavidRoss 0:cb2826e4b518 29 buffer[i]=0; // set element to NULL character
DavidRoss 0:cb2826e4b518 30 }
DavidRoss 0:cb2826e4b518 31 lcd.clear(); // clear lcd screen
DavidRoss 0:cb2826e4b518 32 lcd.locate(0,0); // 1st column 1st row
DavidRoss 0:cb2826e4b518 33 lcd.print("0123456789012345"); // print grid 0-15
DavidRoss 0:cb2826e4b518 34 lcd.setRGB(0x00,0x00,0xff); // set background to blue
DavidRoss 0:cb2826e4b518 35 for(;;) // infinite loop
DavidRoss 0:cb2826e4b518 36 {
DavidRoss 0:cb2826e4b518 37 voltage=pot.read(); // voltage reading (0-1) from pot
DavidRoss 0:cb2826e4b518 38 voltage=3.33*voltage; // scale to 3.33 volts
DavidRoss 0:cb2826e4b518 39 lcd.locate(3,1); // 4th column 2nd row
DavidRoss 0:cb2826e4b518 40 sprintf(buffer,"%5.3f",voltage); // voltage to string in buffer
DavidRoss 0:cb2826e4b518 41 lcd.print(buffer); // print buffer on lcd
DavidRoss 0:cb2826e4b518 42 wait(0.05);
DavidRoss 0:cb2826e4b518 43 }
DavidRoss 0:cb2826e4b518 44 }