Skip to content

Instantly share code, notes, and snippets.

@Glavic
Created November 3, 2016 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glavic/91b0863c9c81301e41140d9414e816c5 to your computer and use it in GitHub Desktop.
Save Glavic/91b0863c9c81301e41140d9414e816c5 to your computer and use it in GitHub Desktop.
YT-tutorial-6
// https://www.youtube.com/watch?v=b381xvbp6pw
#include "mbed.h"
DigitalOut ledGreen(LED1);
DigitalOut ledBlue(LED2);
DigitalOut ledRed(LED3);
DigitalIn UserButton(USER_BUTTON);
Serial pc(USBTX, USBRX);
int main() {
ledGreen = 1;
ledBlue = 1;
ledRed = 1;
//pc.baud(14400);
pc.printf("Hello world!\r\n");
while (true) {
if (pc.readable()) {
char command = pc.getc();
switch (command) {
case 'R':
case 'r':
pc.printf("Red LED toogled...\r\n");
ledRed = !ledRed;
break;
case 'G':
case 'g':
ledGreen = !ledGreen;
break;
case 'B':
case 'b':
ledBlue = !ledBlue;
break;
case 'H':
case 'h':
pc.printf("Type R to toggle Red LED\r\n");
pc.printf("Type C to turn OFF all LED\r\n");
pc.printf("Type A to turn ON all LED\r\n");
break;
case 'C':
case 'c':
pc.printf("Turned all OFF...\r\n");
ledGreen = 0;
ledBlue = 0;
ledRed = 0;
break;
case 'A':
case 'a':
pc.printf("Turned all ON...\r\n");
ledGreen = 1;
ledBlue = 1;
ledRed = 1;
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment