Taras Popiv / Mbed OS GL_task

main.cpp

Committer:
gjgsd
Date:
2017-12-09
Revision:
3:dd96529b7ae9
Parent:
2:35f13b7f3659
Child:
4:d4aeacb47955

File content as of revision 3:dd96529b7ae9:

#include "mbed.h"

void print_char(char c = '*')
{
    printf("%c", c);
    fflush(stdout);
}

Thread thread;
Thread thread1;
int print = 1;
char input [64];
int lamp = 50;

//DigitalOut led1(LED1);
PwmOut led1(D11);
//PwmOut led2(D13);

void print_thread()
{
    while (true) {
        
        if (print == 1) {
//          printf("\r\n*** Do you love me too?  ***\r\n");
          printf("\r\nLamp is ON\r\n");
          printf("\r\nPlese type + or - to change brightness\r\n");
          print = 0;
        }
        scanf("%s",input);
        printf("\r\n* %s *\r\n",input);
        if (!strcmp(input,"-")){
         if (lamp < 90) lamp = lamp + 10;
         else if (lamp < 100) lamp = lamp + 1;
         printf("\r\n*** Lamp brightness is %d ***\r\n", lamp);
        }
        else if (!strcmp(input,"+")){
          printf("\r\n*** %d ***\r\n", lamp);  
          if (lamp > 10) lamp = lamp - 10; 
          else if (lamp > 0) lamp = lamp - 1; 
          printf("\r\n*** Lamp brightness is %d ***\r\n", lamp);
        }
        else {
          printf("\r\n(plese type + or -)\r\n");
        }
    }
}

int main()
{
    printf("\r\n*** Welcome ***\n\r");

    thread.start(print_thread);
    

    while (true) {
        led1 = (0.01 * lamp);
//          led2 = !led2;
        wait(0.2);
//         led1 = led1 + 0.01;
//         wait(0.2);
//         if(led1 == 1.0) {
//             led1 = 0;
//         }
        
        }

}