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
Fork of hybrid_arm_main by
main.cpp
- Committer:
- hare
- Date:
- 2016-05-13
- Revision:
- 10:be0892c68789
- Parent:
- 9:57fb67f05375
File content as of revision 10:be0892c68789:
#include "mbed.h" DigitalIn start_sw(p25); PwmOut motor_up(p23); PwmOut motor_down(p22); DigitalIn encoder_A(p16); DigitalIn encoder_B(p17); AnalogIn sensor(p20); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); CAN can1(p30,p29); PwmOut fan(p21); Ticker can_sub; char send_data[4]={}; int pattern=1; int degree=0; int river_eco_loca=0; void receive(){ CANMessage msg; if(can1.read(msg)){ if(msg.id==5){ river_eco_loca=msg.data[1]; //(short)((msg.data[2]<<8)|(msg.data[3])); printf("%river=%d\n\r",river_eco_loca); led4=!led4; } } send_data[0] = degree >> 8; send_data[1] = degree & 255; send_data[2] = pattern; can1.write(CANMessage(6, send_data, 3)); // printf("1\n\r"); } int fan_power=1100; int main(){ motor_up.period_us(20); motor_down.period_us(20); can_sub.attach_us(&receive,10000); can1.frequency(1000000); motor_up=0; motor_down=0; degree=90; wait(0.3); fan.period_ms(20); fan.pulsewidth_us(1100); printf("connect battery in 5sec please\n\r"); for(int p=0;p<5;p++){ led1=1; wait(0.6); led1=0; wait(0.4);} // connect ripo in 5s; printf("4sec is count down\n\r"); for(int p=0;p<4;p++){ led1=1; led2=1; wait(0.6); led2=0; wait(0.4); } printf("fan and is running\n\r"); led1=1; led2=1; led3=1; while(1){ switch(river_eco_loca){ case 0: fan_power=1100; break; case 1: fan_power=1500; //start break; case 2: fan_power=1700;degree=70; break; case 3: fan_power=1100; led1=0;led2=0;led3=0; break; default: fan_power=1100; break;} fan.pulsewidth_us(fan_power); } }