Candy PERES
/
can_speaker
TP3 - Réseau terrain de supervision : CAN
Diff: test_main.cpp
- Revision:
- 2:468ee5a130a1
- Parent:
- 0:04e1f0fec163
--- a/test_main.cpp Tue May 23 06:59:12 2017 +0000 +++ b/test_main.cpp Tue May 23 08:09:24 2017 +0000 @@ -2,21 +2,93 @@ #define LA_440 2273 + DigitalOut myled(LED1); +PwmOut Speaker(p21); + + +CAN CanPort(p30, p29); + +CANMessage MessageRx; +CANMessage MessageTx; + + +unsigned int Id; + + + +void canReader(void) +{ +printf("Coucou\n"); + if (CanPort.read(MessageRx)) + { + myled = !myled; + if ( MessageRx.id == 0x111) + { + switch (MessageRx.data[0]){ + case 0x01 : + Speaker.write(0.2); + wait(0.1); + Speaker.write(0.2); + wait(0.1); + break; + + case 0x11 : + Speaker.write(1); + wait(0.1); + break; + + default : + Speaker.write(0.1); + wait(0.1); + Speaker.write(0.1); + wait(0.1); + Speaker.write(0.1); + wait(0.1); + Speaker.write(0.1); + wait(0.1); + Speaker.write(0.1); + wait(0.1); + Speaker.write(0.1); + wait(0.1); + + } + myled = !myled; + } + } +} + + int main() { -PwmOut Speaker(p21); + + + CanPort.frequency(20000); + + MessageRx.len=1; + + //MessageTx.format = CANStandard; + //MessageTx.format = CANExtended; + + //MessageTx.type = CANData; + //MessageTx.type = CANRemote; + + CanPort.attach(canReader,CAN::RxIrq); + + //threadA.start(thA); + //threadB.start(thB); + + myled = 0; + printf("Start OK\n"); + Speaker.period_us(LA_440); Speaker.write(0); while(1) { - Speaker.write(0); - wait(1); - Speaker.write(0.5); - wait(0.3); + } }