Bryce Himebaugh
/
motor_buffer
Pager Motor Example
main.cpp@5:e2c4377fac6d, 2021-12-03 (annotated)
- Committer:
- bhimebau
- Date:
- Fri Dec 03 14:37:49 2021 +0000
- Revision:
- 5:e2c4377fac6d
- Parent:
- 4:aaa50ac098c9
low freq buzzing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bhimebau | 0:f7d9662c6d11 | 1 | |
bhimebau | 0:f7d9662c6d11 | 2 | #include "mbed.h" |
bhimebau | 0:f7d9662c6d11 | 3 | #include "platform/mbed_thread.h" |
bhimebau | 0:f7d9662c6d11 | 4 | #include <string.h> |
bhimebau | 0:f7d9662c6d11 | 5 | |
bhimebau | 4:aaa50ac098c9 | 6 | // PWM Frequency |
bhimebau | 5:e2c4377fac6d | 7 | #define PFREQ .5 |
bhimebau | 4:aaa50ac098c9 | 8 | |
bhimebau | 0:f7d9662c6d11 | 9 | |
bhimebau | 0:f7d9662c6d11 | 10 | Serial pc(USBTX, USBRX); // tx, rx |
bhimebau | 2:007b4fa1f64e | 11 | PwmOut p1(PA_8); |
bhimebau | 0:f7d9662c6d11 | 12 | |
bhimebau | 0:f7d9662c6d11 | 13 | int main() |
bhimebau | 0:f7d9662c6d11 | 14 | { |
bhimebau | 0:f7d9662c6d11 | 15 | char cmd[80]; |
bhimebau | 0:f7d9662c6d11 | 16 | char ch; |
bhimebau | 0:f7d9662c6d11 | 17 | unsigned char index = 0; |
bhimebau | 0:f7d9662c6d11 | 18 | |
bhimebau | 0:f7d9662c6d11 | 19 | // Initialise the digital pin LED1 as an output |
bhimebau | 0:f7d9662c6d11 | 20 | DigitalOut led(LED1); |
bhimebau | 4:aaa50ac098c9 | 21 | p1.period((float)1/PFREQ); |
bhimebau | 2:007b4fa1f64e | 22 | p1.write(0.0); |
bhimebau | 3:2e70eaa59446 | 23 | pc.printf("\n\rMotor> "); |
bhimebau | 0:f7d9662c6d11 | 24 | while (true) { |
bhimebau | 0:f7d9662c6d11 | 25 | |
bhimebau | 0:f7d9662c6d11 | 26 | ch = pc.getc(); |
bhimebau | 0:f7d9662c6d11 | 27 | index = 0; |
bhimebau | 0:f7d9662c6d11 | 28 | while ((ch != '\n') && (ch != '\r')) { |
bhimebau | 0:f7d9662c6d11 | 29 | pc.putc(ch); |
bhimebau | 0:f7d9662c6d11 | 30 | cmd[index++] = ch; |
bhimebau | 0:f7d9662c6d11 | 31 | ch = pc.getc(); |
bhimebau | 0:f7d9662c6d11 | 32 | } |
bhimebau | 0:f7d9662c6d11 | 33 | cmd[index] = 0; |
bhimebau | 0:f7d9662c6d11 | 34 | if (!strcmp(cmd,"lon")) { |
bhimebau | 0:f7d9662c6d11 | 35 | led = 1; |
bhimebau | 0:f7d9662c6d11 | 36 | } |
bhimebau | 0:f7d9662c6d11 | 37 | else if (!strcmp(cmd,"lof")) { |
bhimebau | 0:f7d9662c6d11 | 38 | led = 0; |
bhimebau | 0:f7d9662c6d11 | 39 | } |
bhimebau | 3:2e70eaa59446 | 40 | else if (!strcmp(cmd,"high")) { |
bhimebau | 2:007b4fa1f64e | 41 | p1.write(1.0); |
bhimebau | 2:007b4fa1f64e | 42 | } |
bhimebau | 3:2e70eaa59446 | 43 | else if (!strcmp(cmd,"med")) { |
bhimebau | 2:007b4fa1f64e | 44 | p1.write(0.5); |
bhimebau | 2:007b4fa1f64e | 45 | } |
bhimebau | 3:2e70eaa59446 | 46 | else if (!strcmp(cmd,"low")) { |
bhimebau | 2:007b4fa1f64e | 47 | p1.write(0.15); |
bhimebau | 2:007b4fa1f64e | 48 | } |
bhimebau | 3:2e70eaa59446 | 49 | else if (!strcmp(cmd,"off")) { |
bhimebau | 2:007b4fa1f64e | 50 | p1.write(0.0); |
bhimebau | 2:007b4fa1f64e | 51 | } |
bhimebau | 2:007b4fa1f64e | 52 | |
bhimebau | 2:007b4fa1f64e | 53 | pc.printf("\n\r"); |
bhimebau | 3:2e70eaa59446 | 54 | pc.printf("Motor> "); |
bhimebau | 0:f7d9662c6d11 | 55 | } |
bhimebau | 0:f7d9662c6d11 | 56 | } |
bhimebau | 1:48e24393d6d9 | 57 |