Base library for various projects.
Base library for various projects.
Revision 0:a2d01ba1a81b, committed 2013-08-01
- Comitter:
- Searle95
- Date:
- Thu Aug 01 09:05:54 2013 +0000
- Child:
- 1:a5f21c409f51
- Commit message:
- Modified for use in this project.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Functions.cpp Thu Aug 01 09:05:54 2013 +0000 @@ -0,0 +1,202 @@ +#include "Functions.h" +#include "screens.h" +#include "variables.h" + +PwmOut led1(LED1); +PwmOut led2(LED2); +PwmOut led3(LED3); +PwmOut led4(LED4); +int loading_loop; +int loading_line; + +void Functions::Loading() { + lcd.cls(); + lcd.writeString(10, 2, "Please wait", NORMAL); + + while(loading_loop < 82) { + wait(0.05); + lcd.writeString(loading_line, 2, ".", NORMAL); + loading_line += 1; + if(loading_line == 82) { + lcd.cls(); + lcd.writeString(25, 2, "Ready!", NORMAL); + } + loading_loop += 1; + } +} + +void Functions::Intro() { + lcd.init(); + lcd.cls(); + lcd.writeString(19, 2, "Welcome!", NORMAL); + wait(1); + lcd.cls(); + lcd.writeString(24, 1, "LEDFun", NORMAL); + lcd.writeString(26, 2, "V1.00", NORMAL); + lcd.writeString(13, 3, "Dan Searle", NORMAL); + wait(5); +} + +void Functions::Commands() { + lcd.cls(); + lcd.writeString(2, 2, "Continue = c", NORMAL); + lcd.writeString(2, 3, "Skip = x", NORMAL); + char c = pc.getc(); + if(c == 'x') { + Loading(); + } + else if(c == 'c') { + lcd.cls(); + lcd.printf(" All = q "); + lcd.printf(" LED 1 = w & a"); + lcd.printf(" LED 2 = e & s"); + lcd.printf(" LED 3 = r & d"); + lcd.printf(" LED 4 = t & f"); + lcd.printf(" All = y "); + wait(5); + Loading(); + } +} + +void Functions::LEDAndRestart() { + double all_bright = 0.0; + double led1_bright = 0.0; + double led2_bright = 0.0; + double led3_bright = 0.0; + double led4_bright = 0.0; + + while(1) { + char c = pc.getc(); + if((c == 'q') && (all_bright < 0.9)) { + led1_bright += 1.0; + led2_bright += 1.0; + led3_bright += 1.0; + led4_bright += 1.0; + all_bright += 1.0; + led1 = led1_bright; + led2 = led2_bright; + led3 = led3_bright; + led4 = led4_bright; + lcd.cls(); + lcd.writeString(5, 2, "All LED's On!", NORMAL); + lcd.writeString(13, 4, "Brightness", NORMAL); + lcd.printf("\n\n\n\n\n\n\n\n\n%g", all_bright); + } + + if((c == 'y') && (all_bright > 0.0)) { + led1_bright -= 1.0; + led2_bright -= 1.0; + led3_bright -= 1.0; + led4_bright -= 1.0; + all_bright -= 1.0; + led1 = led1_bright; + led2 = led2_bright; + led3 = led3_bright; + led4 = led4_bright; + if(all_bright < 0.01) { + all_bright = 0; + } + lcd.cls(); + lcd.writeString(2, 2, "All LED's Off!", NORMAL); + lcd.writeString(13, 4, "Brightness", NORMAL); + lcd.printf("\n\n\n\n\n\n\n\n\n%g", all_bright); + } + + if((c == 'w') && (led1_bright < 0.9)) { + led1_bright += 0.1; + led1 = led1_bright; + lcd.cls(); + lcd.writeString(15, 2, "LED 1 Up!", NORMAL); + lcd.writeString(13, 4, "Brightness", NORMAL); + lcd.printf("\n\n\n\n\n\n\n\n\n%g", led1_bright); + } + + if((c == 'a') && (led1_bright > 0.0)) { + led1_bright -= 0.1; + led1 = led1_bright; + if(led1_bright < 0.01) { + led1_bright = 0; + } + lcd.cls(); + lcd.writeString(10, 2, "LED 1 Down!", NORMAL); + lcd.writeString(13, 4, "Brightness", NORMAL); + lcd.printf("\n\n\n\n\n\n\n\n\n%g", led1_bright); + } + + if((c == 'e') && (led2_bright < 0.9)) { + led2_bright += 0.1; + led2 = led2_bright; + lcd.cls(); + lcd.writeString(15, 2, "LED 2 Up!", NORMAL); + lcd.writeString(13, 4, "Brightness", NORMAL); + lcd.printf("\n\n\n\n\n\n\n\n\n%g", led2_bright); + } + + if((c == 's') && (led2_bright > 0.0)) { + led2_bright -= 0.1; + led2 = led2_bright; + if(led2_bright < 0.01) { + led2_bright = 0; + } + lcd.cls(); + lcd.writeString(10, 2, "LED 2 Down!", NORMAL); + lcd.writeString(13, 4, "Brightness", NORMAL); + lcd.printf("\n\n\n\n\n\n\n\n\n%g", led2_bright); + } + + if((c == 'r') && (led3_bright < 0.9)) { + led3_bright += 0.1; + led3 = led3_bright; + lcd.cls(); + lcd.writeString(15, 2, "LED 3 Up!", NORMAL); + lcd.writeString(13, 4, "Brightness", NORMAL); + lcd.printf("\n\n\n\n\n\n\n\n\n%g", led3_bright); + } + + if((c == 'd') && (led3_bright > 0.0)) { + led3_bright -= 0.1; + led3 = led3_bright; + if(led3_bright < 0.01) { + led3_bright = 0; + } + lcd.cls(); + lcd.writeString(10, 2, "LED 3 Down!", NORMAL); + lcd.writeString(13, 4, "Brightness", NORMAL); + lcd.printf("\n\n\n\n\n\n\n\n\n%g", led3_bright); + } + + if((c == 't') && (led4_bright < 0.9)) { + led4_bright += 0.1; + led4 = led4_bright; + lcd.cls(); + lcd.writeString(15, 2, "LED 4 Up!", NORMAL); + lcd.writeString(13, 4, "Brightness", NORMAL); + lcd.printf("\n\n\n\n\n\n\n\n\n%g", led4_bright); + } + + if((c == 'f') && (led4_bright > 0.0)) { + led4_bright -= 0.1; + led4 = led4_bright; + if(led4_bright < 0.01) { + led4_bright = 0; + } + lcd.cls(); + lcd.writeString(10, 2, "LED 4 Down!", NORMAL); + lcd.writeString(13, 4, "Brightness", NORMAL); + lcd.printf("\n\n\n\n\n\n\n\n\n%g", led4_bright); + } + + if(c == 'z') { + lcd.cls(); + lcd.writeString(24, 2, "System", NORMAL); + lcd.writeString(22, 3, "Restart", NORMAL); + all_bright = 1; + led1 = all_bright; + led2 = all_bright; + led3 = all_bright; + led4 = all_bright; + wait(2); + NVIC_SystemReset(); + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Functions.h Thu Aug 01 09:05:54 2013 +0000 @@ -0,0 +1,20 @@ +#ifndef FUNCTIONS_H +#define FUNCTIONS_H + +class Functions { + +public: + /*Display revision details and initialise lcd screen*/ + void Intro(); + + /*Display brightness control commands*/ + void Commands(); + + /*Create and display a loading screen*/ + void Loading(); + + /*Take input from pc keyboard through serial and control led brightness using numerous keys*/ + void LEDAndRestart(); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/screens.h Thu Aug 01 09:05:54 2013 +0000 @@ -0,0 +1,10 @@ +#ifndef SCREENS_H +#define SCREENS_H + +#include "N3310LCD.h" +#include "N3310SPIConfig.h" + +static N3310LCD lcd(N3310SPIPort::MOSI, N3310SPIPort::MISO, N3310SPIPort::SCK, N3310SPIPort::CE, N3310SPIPort::DAT_CMD, N3310SPIPort::LCD_RST, N3310SPIPort::BL_ON); +static Serial pc(USBTX, USBRX); + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/variables.h Thu Aug 01 09:05:54 2013 +0000 @@ -0,0 +1,7 @@ +#ifndef VARIABLES_H +#define VARIABLES_H + +extern int loading_loop; +extern int loading_line; + +#endif \ No newline at end of file