Unix-style Fortune teller text display on LCD

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed

Committer:
alexcrepory
Date:
Thu Mar 12 18:02:40 2015 +0000
Revision:
3:410dd2cf0155
Parent:
2:7507d0c0e509
2.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alexcrepory 0:672a66c015ca 1 #include "mbed.h"
alexcrepory 0:672a66c015ca 2 #include "SDFileSystem.h"
alexcrepory 0:672a66c015ca 3 #include "uLCD_4DGL.h"
alexcrepory 0:672a66c015ca 4
alexcrepory 0:672a66c015ca 5 SDFileSystem sd(p11, p12, p13, p14, "sd"); //sd card
alexcrepory 0:672a66c015ca 6 DigitalIn pb(p21); //pushbutton
alexcrepory 0:672a66c015ca 7 uLCD_4DGL uLCD(p9,p10,p8); // serial tx, serial rx, reset pin;
alexcrepory 0:672a66c015ca 8
alexcrepory 0:672a66c015ca 9 int main() {
alexcrepory 0:672a66c015ca 10 char buffer[300]; //buffer to store the quotation
alexcrepory 0:672a66c015ca 11 float rando=0; //variable responsible to receive the random value
alexcrepory 0:672a66c015ca 12 uLCD.cls(); //clear the screen
alexcrepory 2:7507d0c0e509 13
alexcrepory 0:672a66c015ca 14 while (true){
alexcrepory 0:672a66c015ca 15 if (pb == 1){
alexcrepory 0:672a66c015ca 16 //open the file to be read
alexcrepory 2:7507d0c0e509 17 FILE *ft = fopen("/sd/sdtest.txt", "r+");
alexcrepory 0:672a66c015ca 18 if(ft == NULL) {
alexcrepory 0:672a66c015ca 19 error("Could not open file for write\n");
alexcrepory 0:672a66c015ca 20 }
alexcrepory 0:672a66c015ca 21 rando = rand()%10+1;//random value
alexcrepory 0:672a66c015ca 22 for(int i=0; i<rando; i++){ //copy to buffer the quotation of the random value
alexcrepory 0:672a66c015ca 23 fgets(buffer, 300, ft);
alexcrepory 0:672a66c015ca 24 }
alexcrepory 2:7507d0c0e509 25 uLCD.background_color(WHITE);
alexcrepory 0:672a66c015ca 26 uLCD.cls();
alexcrepory 2:7507d0c0e509 27 uLCD.background_color(WHITE);
alexcrepory 2:7507d0c0e509 28 uLCD.textbackground_color(WHITE);
alexcrepory 2:7507d0c0e509 29 uLCD.color(BLACK);
alexcrepory 0:672a66c015ca 30 uLCD.printf("%s\n", buffer); //prints in the scrren the string
alexcrepory 0:672a66c015ca 31 fclose(ft);
alexcrepory 0:672a66c015ca 32 wait(0.2);
alexcrepory 0:672a66c015ca 33 }
alexcrepory 0:672a66c015ca 34 }
alexcrepory 0:672a66c015ca 35 }