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: WS2812 PixelArray Adafruit_GFX HC_SR04_Ultrasonic_Library
main.cpp
00001 #include "mbed.h" 00002 #include "RemoteIR.h" 00003 #include "ReceiverIR.h" 00004 #include "TB6612FNG.h" 00005 #include "TRSensors.h" 00006 #include "ultrasonic.h" 00007 #include "Adafruit_SSD1306.h" 00008 #include "WS2812.h" 00009 #include "PixelArray.h" 00010 00011 #define button_SENSORS 5 00012 #define ADT7420_TEMP_REG (0x00) 00013 #define ADT7420_CONF_REG (0x03) 00014 #define EVAL_ADT7420_ADDR (0x48) 00015 #define PCF8574_ADDR (0x20) 00016 #define WS2812_BUF 100 00017 #define WS2812_BUF2 4 00018 #define NUM_COLORS 3 00019 #define NUM_LEDS_PER_COLOR 4 00020 00021 // create object 00022 DigitalOut dc(D8,1); 00023 DigitalOut rst(D9,1); 00024 I2C i2c(I2C_SDA, I2C_SCL); 00025 TB6612FNG motorDriver(D6, A1, A0, D5, A2, A3); 00026 Ultrasonic ultra(D3, D2, .1, false); 00027 ReceiverIR IR(D4); 00028 TRSensors trs; 00029 RawSerial pc(USBTX, USBRX, 115200); 00030 Adafruit_SSD1306_I2c gOled2(i2c,D9,0x7A,64,128); 00031 Timer timer; 00032 PixelArray px(WS2812_BUF); 00033 WS2812 ws(D7, WS2812_BUF, 7, 15, 10, 15); 00034 00035 00036 volatile int button = 0; 00037 00038 // PID variables 00039 static float pval = 0; 00040 00041 // motor Driver 00042 float fPwmAPeriod; 00043 float fPwmAPulsewidth; 00044 float fPwmBPeriod; 00045 float fPwmBPulsewidth; 00046 00047 inline void update_display(){ 00048 gOled2.clearDisplay(); 00049 gOled2.setTextCursor(0,0); 00050 gOled2.printf("E-RON alphabot\r\n"); 00051 gOled2.printf("P: %.2f\r\n",pval); 00052 gOled2.display(); 00053 } 00054 00055 int colorbuf[NUM_COLORS] = {0xff0000,0x00ff00,0x0000ff}; 00056 int colorbuf3 =0x000000; 00057 00058 int main() 00059 { 00060 00061 for (int i = 0; i < WS2812_BUF; i++) { 00062 px.Set(i, colorbuf[(i / NUM_LEDS_PER_COLOR) % NUM_COLORS]); 00063 } 00064 00065 for (int j=0; j<WS2812_BUF; j++) { 00066 // px.SetI(pixel position, II value) 00067 px.SetI(j%WS2812_BUF, 0xf+(0xf*4)); 00068 } 00069 00070 update_display(); 00071 00072 RemoteIR::Format format; 00073 uint8_t buf[32]; 00074 int bitcount; 00075 while(1) 00076 { // read the value of the code 00077 if (IR.getState() == ReceiverIR::Received) 00078 { 00079 bitcount = IR.getData(&format, buf, sizeof(buf) * 8); 00080 pc.printf("%d\r\n", bitcount); 00081 pc.printf("buf[2]: %d\r\n", buf[2]); 00082 button = buf[2]; 00083 } 00084 00085 switch(button) 00086 { 00087 case 0x45: 00088 // ch- button (P value up) 00089 pval += 0.01; 00090 pval = fabs(pval); 00091 update_display(); 00092 wait(0.3); 00093 button = 0x1C; 00094 break; 00095 00096 default: 00097 // wrong button 00098 pc.printf("wrong button!\r\n"); 00099 break; 00100 } 00101 } 00102 }
Generated on Thu Jul 14 2022 07:50:58 by
1.7.2