This is my code:
#include "mbed.h"
#include "C12832.h"
#include "QEI.h"
#define LEFT_MOTOR_PWM PA_15
#define RIGHT_MOTOR_PWM PB_15
#define LEFT_MOTOR_DIRECTION PA_13
#define RIGHT_MOTOR_DIRECTION PB_7
#define RIGHT_MODE PB_12
#define LEFT_MODE PA_13
#define ENABLE2 PC_5
DigitalOut Left_Motor_Direction(LEFT_MOTOR_DIRECTION);
DigitalOut Right_Motor_Direction(RIGHT_MOTOR_DIRECTION);
PwmOut motorPWM(LEFT_MOTOR_PWM); // Motor
PwmOut motorPWMa(RIGHT_MOTOR_PWM); // Motor A
DigitalOut left_mode(LEFT_MODE); // Motor Direction
DigitalOut right_mode(RIGHT_MODE); //Motor A Mode
DigitalOut enable (ENABLE2); // Enable
QEI encoder_left (PC_8,PC_6,NC,256);
QEI encoder_right (PA_12,PA_11,NC,256);
C12832 lcd(D11, D13, D12, D7, D10);
InterruptIn fire (D4);
InterruptIn up (A2);
InterruptIn down (A3);
InterruptIn left (A4);
InterruptIn right (A5);
int main () {
while(1) {
motorPWM.period_ms (0.3); // Enable Motors
motorPWMa.period_ms (0.3);
Left_Motor_Direction = 1;
Right_Motor_Direction = 1;
left_mode = 1;
right_mode = 1;
enable = 1;
int read_period_us();
if (read_period_us >= 0) {
lcd.cls(); //Clear the screen
lcd.locate(20,0); //Locate at (20,0)
lcd.printf("The Buggy Speed");//Print text
lcd.rect (32,10,96,30,1); //Draw a rectangle from (32,10) to (96,30)
lcd.locate(36,12); //Locate at (36,12)
lcd.printf("Is"); //Print text
lcd.locate(64,20); //Locate at (64,20);
lcd.printf(": %i", encoder_left.getRevolutions()); //Print text
wait(1);
}
}
}```
Hello,
be so kind and use these three symbols ``` before and another three after your code in your post. That will format the code for better reading.
Like this -> Click
#include "mbed.h"
#include "C12832.h"
#include "QEI.h"
#define LEFT_MOTOR_PWM PA_15
#define RIGHT_MOTOR_PWM PB_15
#define LEFT_MOTOR_DIRECTION PA_13
#define RIGHT_MOTOR_DIRECTION PB_7
#define RIGHT_MODE PB_12
#define LEFT_MODE PA_13
#define ENABLE2 PC_5
DigitalOut Left_Motor_Direction(LEFT_MOTOR_DIRECTION);
DigitalOut Right_Motor_Direction(RIGHT_MOTOR_DIRECTION);
PwmOut motorPWM(LEFT_MOTOR_PWM); // Motor
PwmOut motorPWMa(RIGHT_MOTOR_PWM); // Motor A
DigitalOut left_mode(LEFT_MODE); // Motor Direction
DigitalOut right_mode(RIGHT_MODE); //Motor A Mode
DigitalOut enable (ENABLE2); // Enable
QEI encoder_left (PC_8,PC_6,NC,256);
QEI encoder_right (PA_12,PA_11,NC,256);
C12832 lcd(D11, D13, D12, D7, D10);
InterruptIn fire (D4);
InterruptIn up (A2);
InterruptIn down (A3);
InterruptIn left (A4);
InterruptIn right (A5);
int main () {
while(1) {
motorPWM.period_ms (0.3); // Enable Motors
motorPWMa.period_ms (0.3);
Left_Motor_Direction = 1;
Right_Motor_Direction = 1;
left_mode = 1;
right_mode = 1;
enable = 1;
int read_period_us();
if (read_period_us >= 0) {
lcd.cls(); //Clear the screen
lcd.locate(20,0); //Locate at (20,0)
lcd.printf(“The Buggy Speed”);//Print text
lcd.rect (32,10,96,30,1); //Draw a rectangle from (32,10) to (96,30)
lcd.locate(36,12); //Locate at (36,12)
lcd.printf(“Is”); //Print text
lcd.locate(64,20); //Locate at (64,20);
lcd.printf(": %i", encoder_left.getRevolutions()); //Print text
wait(1);
}
}
}
What is this?
int read_period_us();
if (read_period_us >= 0) {
It looks like a function declaration, but inside the main
and without a definition. It certainly doesn’t look like something that can be compiled.
Something like that below would make more sense.
if (motorPWM.read_period_us() >= 0) {
BR, Jan
It is from the PWM mBed API, I am using it to read the pulsewidth period, however the same fault appears even when I comment that specific part out.
#include "C12832.h"
#include "QEI.h"
#define LEFT_MOTOR_PWM PA_15
#define RIGHT_MOTOR_PWM PB_15
#define LEFT_MOTOR_DIRECTION PA_13
#define RIGHT_MOTOR_DIRECTION PB_7
#define RIGHT_MODE PB_12
#define LEFT_MODE PA_13
#define ENABLE2 PC_5
DigitalOut Left_Motor_Direction(LEFT_MOTOR_DIRECTION);
DigitalOut Right_Motor_Direction(RIGHT_MOTOR_DIRECTION);
PwmOut motorPWM(LEFT_MOTOR_PWM); // Motor
PwmOut motorPWMa(RIGHT_MOTOR_PWM); // Motor A
DigitalOut left_mode(LEFT_MODE); // Motor Direction
DigitalOut right_mode(RIGHT_MODE); //Motor A Mode
DigitalOut enable (ENABLE2); // Enable
QEI encoder_left (PC_8,PC_6,NC,256);
QEI encoder_right (PA_12,PA_11,NC,256);
C12832 lcd(D11, D13, D12, D7, D10);
InterruptIn fire (D4);
InterruptIn up (A2);
InterruptIn down (A3);
InterruptIn left (A4);
InterruptIn right (A5);
int main () {
while(1) {
motorPWM.period_ms (0.3); // Enable Motors
motorPWMa.period_ms (0.3);
Left_Motor_Direction = 1;
Right_Motor_Direction = 1;
left_mode = 1;
right_mode = 1;
enable = 1;
/*
int read_period_us();
if (read_period_us >= 0) { */
lcd.cls(); //Clear the screen
lcd.locate(20,0); //Locate at (20,0)
lcd.printf("The Buggy Speed");//Print text
lcd.rect (32,10,96,30,1); //Draw a rectangle from (32,10) to (96,30)
lcd.locate(36,12); //Locate at (36,12)
lcd.printf("Is"); //Print text
lcd.locate(64,20); //Locate at (64,20);
lcd.printf(": %i", encoder_left.getRevolutions()); //Print text
wait(1);
//}
}
}
Point was about your statement
Only 3 symbols and you can edit your first post via a pen icon.
About your problem.
Maybe the interrupts are the reason. So try to insert a printf
to your while loop and check the output in a PC terminal application.
printf("running\n");
You will see it only first time, I think.
BR, Jan