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-rtos mbed Servo Motor SoftPWM
main.cpp
- Committer:
- cwang776
- Date:
- 2022-11-16
- Revision:
- 6:9721eae5ec03
- Parent:
- 1:965e202877f7
File content as of revision 6:9721eae5ec03:
#include "mbed.h"
#include "rtos.h"
Thread ir_transmit_thread;
Thread ir_receive_thread;
// IR
Serial pc(USBTX, USBRX); // tx, rx
Serial device(p13, p14); // tx, rx
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
PwmOut IRLED(p21);
// Lives LEDs
BusOut lives_leds(p5, p6, p7);
// Speaker
PwmOut speaker(p25);
void decrease_lives() {
if (lives_leds == 7) {
lives_leds = 3;
} else if (lives_leds == 3) {
lives_leds = 1;
} else {
lives_leds = 0;
}
}
void ir_receive () {
//IR send and receive demo
//LED1 and LED2 indicate TX/RX activity
//Character typed in PC terminal application sent out and returned back using IR transmitter and receiver
//IR Transmit code
IRLED.period(1.0/38000.0);
IRLED = 0.5;
//Drive IR LED data pin with 38Khz PWM Carrier
//Drive IR LED gnd pin with serial TX
device.baud(2400);
while(1) {
if(pc.readable()) {
myled1 = 1;
device.putc(pc.getc());
decrease_lives();
myled1 = 0;
}
}
}
// this would be controlled by bluetooth
void ir_transmit() {
while(1) {
//IR Receive code
if(device.readable()) {
myled2 = 1;
pc.putc(device.getc());
myled2 = 0;
}
}
}
int main() {
// light up all 3 lives leds
lives_leds = 7;
ir_transmit_thread.start(ir_transmit);
ir_receive_thread.start(ir_receive);
}
