Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Servo USBDevice n-DAP_MODBUS_FEEDER_ADC
Diff: main.cpp
- Revision:
- 0:fe1478e69a3b
- Child:
- 1:d3ba80dea3dc
diff -r 000000000000 -r fe1478e69a3b main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Feb 22 16:28:19 2019 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" +#include "LPC11Uxx.h" +#include "USBSerial.h" +//#include "Servo.h" + + + +DigitalOut red(P0_20); +DigitalOut green(P0_21); +DigitalOut blue(P0_11); +AnalogIn adc1(P0_22); //n-DAP pin 12 +USBSerial serial(0x1f00,0x2012,0x0001,false);// serial over native USB on board (false is non blocking) +Serial modbus(P0_19, P0_18); // tx, rx +DigitalOut dir(P0_2); +PwmOut rcservo(P0_8); + + +int main() { + modbus.baud(9600); + uint8_t buf[32]; + uint8_t i = 0; + uint16_t angle = 0; + + dir = 1; + wait(4); // wait the usb to be recognized from the PC + modbus.printf(" 0x%04u\r", adc1.read_u16()); + serial.printf(" 0x%04u\r", adc1.read_u16()); //adc readout to PC + dir = 0; + green = 1; + blue = 1; + rcservo.period_ms(20); + rcservo.pulsewidth_us(1500) ; + + while(1) { + red = !red; + if(modbus.readable()) { + if (i > 31) { + i = 0; + } + buf[i] = modbus.getc(); + if ( buf[i] == 0x20){ + serial.printf("\n"); //change line and reset index + i = 0; buf[i] = 0x20; + } + modbus.putc(buf[i]); //debug only + serial.printf("0x%02X ", buf[i]); + i++; + } + if (buf[9] == 0x01) { blue = 0;} + if (buf[9] == 0x02) { blue = 1;} + if (buf[9] == 0x03) { green = 0; } + if (buf[9] == 0x04) { green = 1; } + if (buf[9] > 0x00) { + angle = buf[9]*4; + angle = 1000 + angle; + buf[9] =0; + rcservo.period_ms(20); + rcservo.pulsewidth_us(angle) ; + } + + } +}