Candy PERES
/
can_speaker
TP3 - Réseau terrain de supervision : CAN
Diff: test_main.cpp
- Revision:
- 3:478e83703442
- Parent:
- 2:468ee5a130a1
--- a/test_main.cpp Tue May 23 08:09:24 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -#include "mbed.h" - - -#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() -{ - - - 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) - { - - } -}