Alejandro Montes
/
Experiment_1
IT Tralee Life Long Learning 2020 Instrumentation, Monitoring and Control Module Laboratory Session
LAB_2.1.CPP@0:4a236e64d65b, 2020-07-27 (annotated)
- Committer:
- alejandromontes
- Date:
- Mon Jul 27 19:35:12 2020 +0000
- Revision:
- 0:4a236e64d65b
Alejandro Montes Instrumentation Monitoring and Control LAB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alejandromontes | 0:4a236e64d65b | 1 | #include "mbed.h" |
alejandromontes | 0:4a236e64d65b | 2 | |
alejandromontes | 0:4a236e64d65b | 3 | Serial pc(USBTX, USBRX); // tx, rx |
alejandromontes | 0:4a236e64d65b | 4 | PwmOut led(LED1); |
alejandromontes | 0:4a236e64d65b | 5 | float brightness=0.0; |
alejandromontes | 0:4a236e64d65b | 6 | |
alejandromontes | 0:4a236e64d65b | 7 | |
alejandromontes | 0:4a236e64d65b | 8 | int main() { |
alejandromontes | 0:4a236e64d65b | 9 | pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n"); |
alejandromontes | 0:4a236e64d65b | 10 | |
alejandromontes | 0:4a236e64d65b | 11 | while(1) { |
alejandromontes | 0:4a236e64d65b | 12 | char c = pc.getc(); |
alejandromontes | 0:4a236e64d65b | 13 | if((c=='u') && (brightness < 0.5)){ |
alejandromontes | 0:4a236e64d65b | 14 | brightness+=0.01; |
alejandromontes | 0:4a236e64d65b | 15 | led = brightness; |
alejandromontes | 0:4a236e64d65b | 16 | } |
alejandromontes | 0:4a236e64d65b | 17 | if((c=='d')&&(brightness>0.0)){ |
alejandromontes | 0:4a236e64d65b | 18 | brightness-=0.01; |
alejandromontes | 0:4a236e64d65b | 19 | led = brightness; |
alejandromontes | 0:4a236e64d65b | 20 | } |
alejandromontes | 0:4a236e64d65b | 21 | if(c=='u'){ |
alejandromontes | 0:4a236e64d65b | 22 | pc.putc('^'); |
alejandromontes | 0:4a236e64d65b | 23 | } |
alejandromontes | 0:4a236e64d65b | 24 | if(c=='d'){ |
alejandromontes | 0:4a236e64d65b | 25 | pc.putc('v'); |
alejandromontes | 0:4a236e64d65b | 26 | } |
alejandromontes | 0:4a236e64d65b | 27 | } |
alejandromontes | 0:4a236e64d65b | 28 | } |