SEU10f / Mbed 2 deprecated P4

Dependencies:   mbed

pwm.cpp

Committer:
Blasko
Date:
2015-10-20
Revision:
1:0bb74fa30daa
Parent:
0:2263e23eb7e8
Child:
2:4e86f37f1c1c

File content as of revision 1:0bb74fa30daa:

#include "mbed.h"
 
Ticker ticker;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
PwmOut pwmx(p26);
PwmOut pwmy(p25);
CAN can2(p30, p29);
char counter = 0;
int x=0;
int y=0;

#define PERIOD 0.000005
#define MAX 1300.0f
void send() {

 }
int main() {
    printf("main d()\n");
    ticker.attach(&send, 1);
    CANMessage msg;
    can2.frequency(1000000);
    pwmx.period(PERIOD);  // 4 second period
    pwmy.period(PERIOD); 
    while(1) {
      //  printf("loop()\n");
        if(can2.read(msg)) {
            x = ((int) msg.data[5])*255 + ((int)msg.data[4]);
            y = ((int)msg.data[1])*255 + ((int) msg.data[0]);
            pwmx.write(x/MAX); 
            pwmy.write(1-y/MAX); 
            printf("Message received: x %d %d %d %d %d %d %d %d %d %d\r\n",msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7], x , y);
            led2 = !led2;
        } 
        wait(0.05);
    }
}