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.
main.cpp
- Committer:
- yuki0701
- Date:
- 2019-01-12
- Revision:
- 0:0deb9ab4a262
- Child:
- 1:e208df501049
File content as of revision 0:0deb9ab4a262:
#include "mbed.h"
#include "uw.h"
//CAN can1(p30,p29,1000000);
CAN can1(PA_11,PA_12,1000000);
DigitalOut led(LED1);
Ticker ticker;
Uw uw1(PF_1); //機体背面の超音波センサー(三宝アーム側)
Uw uw2(PF_0); //機体正面の超音波センサー(果物アーム側)
Uw uw3(PB_4); //機体左側の超音波センサー
Uw uw4(PA_0); //機体右側の超音波センサー
//char can_data1[2]={0,0};
//char can_data2[2]={0,0};
char can_data3[2]={0,0};
//char can_data4[2]={0,0};
int x;
int data1, data2, data3, data4;
void can_read(){
CANMessage msg;
if(can1.read(msg)){
if(msg.id == 1){
led = 1;
x = (short)((msg.data[0]<<8) | msg.data[1]);
printf("%d:%d,%d\n\r",msg.data[0],msg.data[1],x);
}
}
}
void can_send(){
//printf("%f\n\r",uw1.get_dist());
//data1 = (short)(1000 * uw1.get_dist()); //超音波センサーの値を1000倍して送る(受信側で0.001倍して元に戻す)
//data2 = (short)1000 * uw2.get_dist();
data3 = 1000 * uw3.get_dist();
//data4 = 1000 * uw4.get_dist();
//can_data1[0] = data1 >> 8;
//can_data1[1] = data1 &255;
//can_data2[0] = data2 >> 8;
//can_data2[1] = data2 &255;
can_data3[0] = data3 >> 8;
can_data3[1] = data3 &255;
/*can_data4[0] = data4 >> 8;
can_data4[1] = data4 &255;*/
/*if(can1.write(CANMessage(1,can_data1,2))){
led = 1;
printf("send-data1 = %f", uw1.get_dist());
printf("send-data1 = %f\n\r", 0.01 * data1);
}*/
// if(can1.write(CANMessage(2,can_data2,2))){
// led = 1;
//printf("send-data2\n\r");
// }
if(can1.write(CANMessage(3,can_data3,2))){
led = 1;
printf("send-data3 = %f\n\r", 0.01 * data3);
}
/*if(can1.write(CANMessage(4,can_data4,2))){
//led = 1;
//printf("send-data4\n\r");
}*/
led = 0;
//printf("send-data1 = %f, send-data2 = %f\n\r", 0.01 * data1, 0.01 * data2);
}
int main() {
ticker.attach(&can_send,0.01);
//ticker.attach(&can_read,0.1);
while(1);
/*{
//printf("%f\n\r",uw3.get_dist());
}*/
}