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.
Diff: main.cpp
- Revision:
- 4:c1438ffd88dd
- Parent:
- 3:043e5e06f325
- Child:
- 5:1d817b3c42f1
--- a/main.cpp Thu Jul 11 09:03:23 2019 +0000
+++ b/main.cpp Thu Jul 11 09:29:11 2019 +0000
@@ -1,26 +1,42 @@
#include "mbed.h"
+#include "TextLCD.h"
+#define VMAX 0.36f
+#define VMIN 0.05f
-CAN can1(PB_8, PB_9);
+
Serial pc(USBTX, USBRX, 115200);
-AnalogIn res(PA_0);
Ticker ticker1;
+CAN can1(PB_8, PB_9);
CANMessage can_msg_1;
CANMessage can_msg_send;
-char data_msg[3] = {0x11,0x22,0x33};
+char data_msg[3] = {0x11,0x22,0x33};
+
+
bool armed = false;
+AnalogIn res(PA_0);
+float volt = 0;
+I2C i2c_lcd(PB_7,PB_6); // SDA, SCL
+TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD16x2); // I2C bus, PCF8574 Slaveaddress, LCD Type
+
+const char fill[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00};
+const char empty[] = {0x1F, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x00};
+
+
+void showBar(void);
void CAN_RX1(void);
void sendCMD(void)
{
- //if(armed)
-
- can_msg_send = CANMessage(0x111,data_msg,3,CANData,CANStandard);
- can1.write(can_msg_send);
+ if(armed)
+ {
+ can_msg_send = CANMessage(0x111,data_msg,3,CANData,CANStandard);
+ can1.write(can_msg_send);
+ }
//printf("res: %f\n", res.read());
}
@@ -28,22 +44,23 @@
int main()
{
-
- can1.attach(&CAN_RX1, CAN::RxIrq); //CAN1 Recieve Irq
- ticker1.attach(&sendCMD, 1); //1sec
+ can1.frequency(500000);
+ can1.attach(&CAN_RX1, CAN::RxIrq);
+ ticker1.attach(&sendCMD, 1);
pc.printf("start\n");
- can1.frequency(500000);
+
+
+ lcd.setCursor(TextLCD::CurOff_BlkOff);
+ lcd.setBacklight(TextLCD::LightOn);
+ lcd.setUDC(0, (char *) fill);
+ lcd.setUDC(1, (char *) empty);
+ pc.printf("set done\n\r");
+
while(1)
- {
-
- /*if(can1.read(can_msg_1))
- {
- printf("Message received: %d\n", can_msg_1.data[1]);
- }
- */
-
-
+ {
+ volt = res.read();
+ showBar();
}
}
@@ -58,3 +75,24 @@
}
}
+
+void showBar(void)
+{
+ int bars = 16 * (volt-VMIN)/(VMAX-VMIN);
+ if (bars > 16)
+ bars = 16;
+ else if( bars < 0 )
+ bars = 0;
+
+
+ for(int i = 0; i<bars ;i++)
+ {
+ lcd.locate(i,0);
+ lcd.putc(0);
+ }
+ for(int i = bars; i<16 ;i++)
+ {
+ lcd.locate(i,0);
+ lcd.putc(1);
+ }
+}