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

Dependencies:   4DGL-uLCD-SE mbed

Committer:
jderiso2
Date:
Tue Mar 10 20:06:49 2015 +0000
Revision:
0:50013e3eded8
First Commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jderiso2 0:50013e3eded8 1 #include "mbed.h"
jderiso2 0:50013e3eded8 2 #include "uLCD_4DGL.h"
jderiso2 0:50013e3eded8 3
jderiso2 0:50013e3eded8 4
jderiso2 0:50013e3eded8 5 DigitalOut _led1(LED1);
jderiso2 0:50013e3eded8 6 DigitalOut _led2(LED2);
jderiso2 0:50013e3eded8 7 DigitalOut _led3(LED3);
jderiso2 0:50013e3eded8 8 DigitalOut _led4(LED4);
jderiso2 0:50013e3eded8 9 AnalogIn pot(p20);
jderiso2 0:50013e3eded8 10 uLCD_4DGL lcd(p28, p27, p30);
jderiso2 0:50013e3eded8 11
jderiso2 0:50013e3eded8 12 const int startX = SIZE_X / 3;
jderiso2 0:50013e3eded8 13 const int stopX = startX * 2;
jderiso2 0:50013e3eded8 14 const int stopY = SIZE_Y;
jderiso2 0:50013e3eded8 15 int startY = 0;
jderiso2 0:50013e3eded8 16 void PrintLCDGraph(float value){
jderiso2 0:50013e3eded8 17 int prevY = startY;
jderiso2 0:50013e3eded8 18 startY = SIZE_Y * (1 - value);
jderiso2 0:50013e3eded8 19 // clear part of graph that doesn't overlap between samples
jderiso2 0:50013e3eded8 20 lcd.filled_rectangle(startX, prevY, stopX, startY, BLACK);
jderiso2 0:50013e3eded8 21 lcd.filled_rectangle(startX, startY, stopX, stopY, RED);
jderiso2 0:50013e3eded8 22 }
jderiso2 0:50013e3eded8 23 void PrintLEDGraph(float value){
jderiso2 0:50013e3eded8 24 _led1 = (value >= 0.2) ? 1 : 0;
jderiso2 0:50013e3eded8 25 _led2 = (value >= 0.4) ? 1 : 0;
jderiso2 0:50013e3eded8 26 _led3 = (value >= 0.6) ? 1 : 0;
jderiso2 0:50013e3eded8 27 _led4 = (value >= 0.8) ? 1 : 0;
jderiso2 0:50013e3eded8 28 }
jderiso2 0:50013e3eded8 29 int main() {
jderiso2 0:50013e3eded8 30 float sample;
jderiso2 0:50013e3eded8 31 while(1) {
jderiso2 0:50013e3eded8 32 sample = pot;
jderiso2 0:50013e3eded8 33 PrintLEDGraph(sample);
jderiso2 0:50013e3eded8 34 PrintLCDGraph(sample);
jderiso2 0:50013e3eded8 35 wait(0.1);
jderiso2 0:50013e3eded8 36 }
jderiso2 0:50013e3eded8 37 }