"Hello World" program for using potentiometers with mBed. ECE4180 Lab 4.

Dependencies:   4DGL-uLCD-SE mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "uLCD_4DGL.h"
00003 
00004 
00005 DigitalOut _led1(LED1);
00006 DigitalOut _led2(LED2);
00007 DigitalOut _led3(LED3);
00008 DigitalOut _led4(LED4);
00009 AnalogIn pot(p20);
00010 uLCD_4DGL lcd(p28, p27, p30);
00011 
00012 const int startX = SIZE_X / 3;
00013 const int stopX = startX * 2;
00014 const int stopY = SIZE_Y;
00015 int startY = 0;
00016 void PrintLCDGraph(float value){
00017     int prevY = startY;
00018     startY = SIZE_Y * (1 - value);
00019     // clear part of graph that doesn't overlap between samples
00020     lcd.filled_rectangle(startX, prevY, stopX, startY, BLACK);
00021     lcd.filled_rectangle(startX, startY, stopX, stopY, RED);
00022 }
00023 void PrintLEDGraph(float value){
00024     _led1 = (value >= 0.2) ? 1 : 0;
00025     _led2 = (value >= 0.4) ? 1 : 0;
00026     _led3 = (value >= 0.6) ? 1 : 0;
00027     _led4 = (value >= 0.8) ? 1 : 0;
00028 }
00029 int main() {
00030     float sample;
00031     while(1) {
00032         sample = pot;
00033         PrintLEDGraph(sample);
00034         PrintLCDGraph(sample);
00035         wait(0.1);
00036     }
00037 }