motorComplex.c
/*******************************************************************************
* examples/motorComplex.c *
* ======================= *
* *
* Version: 1.0.5 *
* Date : 07.11.17 *
* Author : Peter Weissig *
* *
* If you are changing this file, you may also consider to update *
* demos/diagnosticTool/diagnosticTool.c *
*******************************************************************************/
//*********************************<Included files>*****************************
#include <tucbot/tucbot.h>
//*********************************<Methods>************************************
void testMotor(void);
int main(void);
//*********************************[testMotor]**********************************
void testMotor(void) {
uint8_t menu_pos = 0;
uint8_t flag_redraw_menu = 0xFF;
int8_t value;
int8_t speed;
int8_t speed_display;
lcdclr();
lcdstr_p(PSTR("Motor -" ));
while (1) {
// redraw menu
if (flag_redraw_menu) {
flag_redraw_menu = 0x00;
lcdxy(0,1);
lcdstr_p(PSTR("####(####)C:####"));
lcdxy(8,0);
if (menu_pos == 0) {
lcdstr_p(PSTR( "left " ));
} else {
lcdstr_p(PSTR( "right" ));
}
speed = 0;
speed_display = -128;
mdelay(400);
}
// check if buttons were pushed
// middle button --> switch menu
mdelay(100);
menu_pos++;
if (menu_pos > 1) {menu_pos = 0;}
flag_redraw_menu = 0xFF;
} else {
// right button --> speed up current motor
mdelay(100);
if (speed < 100) {
speed+= 5;
lcdxy(5,1);
int16tostr(lcdout,speed , 4);
if (menu_pos == 0) {
} else {
}
}
} else {
// no button --> slow down current motor
if (speed > 0) {
speed-= 5;
lcdxy(5,1);
int16tostr(lcdout,speed , 4);
if (menu_pos == 0) {
} else {
}
mdelay( 50);
} else {
mdelay(250);
}
}
}
// update display depending on menu position
if (menu_pos == 0) {
if (motors_received()) {
if (speed_display != value) {
speed_display = value;
lcdxy( 0,1); int16tostr(lcdout,speed_display ,4);
}
}
lcdxy(12,1);
}
} else {
if (motors_received()) {
if (speed_display != value) {
speed_display = value;
lcdxy( 0,1); int16tostr(lcdout,speed_display ,4);
}
}
lcdxy(12,1);
}
}
}
}
//*********************************[main]***************************************
int main (void) {
init_tucbot(0xFF);
testMotor();
return (0);
}
leds_set
void leds_set(eLedMask bitmask, uint8_t bool)
Sets the selected leds on or off.
buttons_get
eButtonMask buttons_get(eButtonMask bitmask)
Returns the last stored value of the selected buttons.
kButtonMiddle
@ kButtonMiddle
bit mask (0x08): middle button
Definition: buttons.h:35
kCurrentGetRight
@ kCurrentGetRight
constants (2): right motor current
Definition: currents.h:45
kModeStudent
@ kModeStudent
constant (1): robot is in student mode
Definition: mode.h:31
kCurrentGetLeft
@ kCurrentGetLeft
constants (1): left motor current
Definition: currents.h:43
kMotorSetAll
@ kMotorSetAll
bit mask (0x03): both motors
Definition: motors.h:47
kMotorSetRight
@ kMotorSetRight
bit mask (0x02): right motor
Definition: motors.h:45
kLedOn
@ kLedOn
constant (0xFF): turn leds on
Definition: leds.h:63
kLedRight
@ kLedRight
bit mask (0x04): right led
Definition: leds.h:46
kMotorGetLeft
@ kMotorGetLeft
constant (kMotorSetLeft): left motor
Definition: motors.h:57
currents_get
uint16_t currents_get(eCurrentGet select)
Returns the last stored current of the selected motor.
kButtonRight
@ kButtonRight
bit mask (0x10): right button
Definition: buttons.h:37
buttons_request
void buttons_request(eRequestType request)
Requests new data from the buttons.
motors_get
int8_t motors_get(eMotorGet select)
Returns the last stored power of the selected motor.
int16tostr
void int16tostr(void *out, int16_t number, uint8_t digits)
Converts an integer to a string and passes it to an output function.
currents_changed
uint8_t currents_changed(void)
Indicates if new data changed the data block sMD_SensCurrent.
kRequestContinuous
@ kRequestContinuous
constant (3): request continuous updates
Definition: update.h:37
kLedMiddle
@ kLedMiddle
bit mask (0x08): middle led
Definition: leds.h:44
kLedOff
@ kLedOff
constant (0x00): turn leds off
Definition: leds.h:61
motors_received
uint8_t motors_received(void)
Indicates if new data for the data block sMD_Motor was received.
lcdclr
void lcdclr(void)
Clears the display.
kMotorGetRight
@ kMotorGetRight
constant (kMotorSetRight): right motor
Definition: motors.h:59
lcdxy
void lcdxy(uint8_t x, uint8_t y)
Moves the cursor to a postion on the display.
mode_set
void mode_set(eMode mode)
Sets the mode of the TUC-Bot.
motors_request
void motors_request(eRequestType request)
Requests new data from the motors.
motors_set
void motors_set(eMotorSetMask select, int8_t power)
Sets the motor power of the selected motor(s).
lcdstr_p
void lcdstr_p(const char *send_data)
Writes a string located in the flash to the display.
kMotorSetLeft
@ kMotorSetLeft
bit mask (0x01): left motor
Definition: motors.h:43
lcdout
void lcdout(uint8_t data)
Writes one byte to the display.
init_tucbot
void init_tucbot(uint8_t enable_interrupts)
Initiates the TUC-Bot.
mdelay
void mdelay(uint16_t mseconds)
Waits for the given time in milliseconds.
currents_request
void currents_request(eRequestType request)
Requests new data from the motor currents.