Use IQS62X sensor and move motor by detected angle
Dependencies: DRV8830 IQS62x IQSDisplayTerminal UIT_ACM1602NI mbed
Fork of Nucleo_ACM1602_I2C_DC by
Revision 7:acb1074eaba6, committed 2017-09-22
- Comitter:
- 8mona
- Date:
- Fri Sep 22 16:27:18 2017 +0000
- Parent:
- 6:e3afb1390167
- Child:
- 8:f7ad1d7176ba
- Commit message:
- Read Angle and speed register from IQS624 sensor
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Sep 21 11:34:27 2017 +0000
+++ b/main.cpp Fri Sep 22 16:27:18 2017 +0000
@@ -50,7 +50,6 @@
Ticker timer_;
I2C i2c(D14, D15);
DRV8830 motor(i2c, DRV8830ADDR_NN);
-//DigitalOut Relay1(D2);
InterruptIn button1(USER_BUTTON);
static float motor_speed;
@@ -58,14 +57,45 @@
// Display elapsed time in minutes and seconds
-void ShowLCD(char * buffer, int startbyte, int endbyte)
+int ReadDegree(char * buffer)
{
- for (int i=startbyte; i<=endbyte; i++) {
- lcd_.WriteValue("%02x ", buffer[i]); // print out in black & white
- }
+ int ret=0;
+
+ //(High bit + Low bit) * 360/65536
+ //ret = ((buffer[0x80]<<8 + buffer[0x81])*0.00549316406 ;
+ ret = (buffer[0x80]<<8 +buffer[0x81])/65536.0*360.0 ;
+ return ret;
}
+int ReadSpeed(char * buffer)
+{
+ int ret=0;
+ ret = (buffer[0x8E]);
+ return ret;
+}
+
+void Displaylevel (int deg)
+{
+
+ int level=deg>>5;
+ lcd_.WriteStringXY("@",0,0);
+ for (int i=0;i<12;i++)
+ {
+ if (i<level)
+ {
+ lcd_.WriteString("-");
+ }
+ else
+ {
+ lcd_.WriteString(" ");
+ }
+ }
+
+
+
+}
+
void TimerIsr()
{
@@ -227,23 +257,29 @@
//if (lcd_.IsConnected()) printf("\r\nConnected");
//else printf("\r\nDisconnected");
- TimerIsr();
+ //TimerIsr();
//timer_.attach(&TimerIsr, 0.1);
- button1.fall(&flip);
-
+ //button1.fall(&flip);
+ //lcd_.WriteStringXY("0",0,0);
+ lcd_.WriteStringXY("Boot1",0,0);
iqs62x.configure(); // configure the ICD
+ lcd_.WriteStringXY("Boot2",0,0);
-
- bool status = motor.status();
- if (status & DRV8830_F_FAULT){
- motor.reset();
- }
+// bool status = motor.status();
+// if (status & DRV8830_F_FAULT){
+// motor.reset();
+// }
while (true) {
- motor.speed(motor_speed);
- //iqs62x.readIqsRegisters(0,NUMBER_OF_REGISTERS); // read all the registers
- //ShowLCD(iqs62x.registers,0x80,0x8f);
- wait(1);
+ iqs62x.readIqsRegisters(0,NUMBER_OF_REGISTERS); // read all the registers
+ int val = ReadDegree(iqs62x.registers);
+ int speed= ReadSpeed(iqs62x.registers);
+
+ lcd_.WriteValueXY("T:%3d ",val, 0,1);
+ lcd_.WriteValue("V:%3d",speed);
+ Displaylevel(val);
+ wait_ms(5);
+
}
}
