Demo program for LCD and Joystick

Dependents:   ELEC2645_Race_Collision

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2019 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  */
00005 
00006 #include "mbed.h"
00007 #include "platform/mbed_thread.h"
00008 #include "Joystick.h"
00009 #include "N5110.h"
00010 
00011 
00012 //VCC,SCE,RST,D/C,MOSI,SCLK,LED
00013 N5110 lcd(p14,p8,p9,p10,p11,p13,p21);
00014 
00015 //                y     x  
00016 Joystick joystick(p20,p19);
00017 
00018 int main()
00019 {
00020     // initialise the LCD and joystick
00021     lcd.init();
00022     lcd.setContrast(0.5);
00023     joystick.init();
00024     
00025     while (1) {
00026         // read the joystick to get the x- and y- values
00027         Vector2D coord = joystick.get_mapped_coord(); 
00028         printf("Coord = %f | %f\n",coord.x,coord.y);    
00029         
00030         lcd.clear();  // clear buffer at the start of the loop
00031         char buffer[14]={0};  // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
00032         sprintf(buffer,"x = %.3f",coord.x); // print formatted data to buffer
00033         lcd.printString(buffer,0,2);     // display on screen
00034         sprintf(buffer,"y = %.3f",coord.y); // print formatted data to buffer
00035         lcd.printString(buffer,0,3);     // display on screen
00036         lcd.refresh();  // need to fresh the screen to get the message to appear
00037         
00038         thread_sleep_for(200);
00039     }
00040 }