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 AQM1602 HMC6352 PID
input.cpp
00001 #include "mbed.h" 00002 #include "extern.h" 00003 00004 //line 00005 void ReadLine(void){ 00006 static uint8_t line_buf[3]={0,0,0}; 00007 wait_us(100); 00008 if(Line[0].read()==1) line_buf[0] = 100; 00009 if(line_buf[0]==0) data.lnFlag[0]=0; 00010 else data.lnFlag[0]=1; 00011 if(line_buf[0]>0) line_buf[0]--; 00012 00013 if(Line[1].read()==1) line_buf[1] = 100; 00014 if(line_buf[1]==0) data.lnFlag[1]=0; 00015 else data.lnFlag[1]=1; 00016 if(line_buf[1]>0) line_buf[1]--; 00017 00018 if(Line[2].read()==1) line_buf[2] = 100; 00019 if(line_buf[2]==0) data.lnFlag[2]=0; 00020 else data.lnFlag[2]=1; 00021 if(line_buf[2]>0) line_buf[2]--; 00022 } 00023 //ball 00024 uint8_t ReadBall(void){//1or0 00025 data.ball = !BallChecker; 00026 return (data.ball>0); 00027 } 00028 void ReadMouse(void){ 00029 if(mouse_sensor.new_motion_data_available()) 00030 { 00031 int16_t delta_x = 0, delta_y = 0; 00032 mouse_sensor.get_delta_x_y(delta_x, delta_y); 00033 data.mouse[0] += delta_x; 00034 data.mouse[1] += delta_y; 00035 } 00036 } 00037 void ReadGyro(void){ 00038 //Data can be got by interrupt. 00039 } 00040 void ReadCmps(void){ 00041 data.cmps = hmc.sample()/10.0; 00042 } 00043 void ReadPing(void){ 00044 uint16_t spi_data; 00045 //Ultra Sonic Wave 00046 spi_ss[1]=0; 00047 wait_us(200); 00048 00049 spi_data = spi.write(0xABCD); 00050 00051 wait_us(200); 00052 spi_ss[1]=1; 00053 00054 data.ping[0] = (spi_data&0x00FF)>>0; 00055 data.ping[1] = (spi_data&0xFF00)>>8; 00056 } 00057 void ValidIr(void){ 00058 if(data.IrFlag==0){ 00059 data.IrFlag=1; 00060 } 00061 } 00062 void ReadIr(void){ 00063 uint16_t spi_data; 00064 00065 //Ir 00066 spi_ss[3]=0; 00067 wait_us(200); 00068 00069 spi_data = spi.write(0xABCD); 00070 00071 wait_us(200); 00072 spi_ss[3]=1; 00073 //key/notice/long/short 00074 data.irKey = (spi_data&0xF000)>>12; 00075 data.irNotice = (spi_data&0x0F00)>>8; 00076 data.irSpot[IR_LONG] = (spi_data&0x00F0)>>4; 00077 data.irSpot[IR_SHORT] = (spi_data&0x000F)>>0; 00078 00079 if(data.irKey!=0xA) data.irNotice=IR_NONE; 00080 if(data.irNotice == IR_NONE) data.irPosition=11; 00081 if(data.irNotice == IR_FAR) data.irPosition=data.irSpot[IR_LONG]-1; 00082 if(data.irNotice == IR_CLOSE) data.irPosition=data.irSpot[IR_SHORT]+7; 00083 if(data.irNotice == IR_CLOSER) data.irPosition=data.irSpot[IR_SHORT]+7; 00084 } 00085 void ReadInfo(void){ 00086 00087 }
Generated on Tue Jul 12 2022 23:12:38 by
