Base library for various projects.

Dependents:   LEDFun NetTester

Base library for various projects.

Functions.cpp

Committer:
Searle95
Date:
2013-08-01
Revision:
0:a2d01ba1a81b
Child:
1:a5f21c409f51

File content as of revision 0:a2d01ba1a81b:

#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();
        }
    }
}