lineComplex.c
/*******************************************************************************
* examples/lineComplex.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 testLine(void);
int main(void);
//*********************************[testLine]***********************************
void testLine(void) {
uint8_t menu_pos = 0;
uint8_t flag_redraw_menu = 0xFF;
uint8_t value;
uint8_t adc_min;
uint8_t adc_max;
lcdclr();
lcdstr_p(PSTR("Line -" ));
while (1) {
// redraw menu
if (flag_redraw_menu) {
flag_redraw_menu = 0x00;
lcdxy(7,0);
switch (menu_pos) {
case 0:
lcdstr_p(PSTR( "digital" ));
lcdxy(0,1); lcdstr_p(PSTR("F:### M:## T:###"));
break;
case 1:
lcdstr_p(PSTR( "front " ));
lcdxy(0,1); lcdstr_p(PSTR("### ### ###"));
break;
default:
lcdstr_p(PSTR( "middle " ));
lcdxy(0,1); lcdstr_p(PSTR("### ###"));
menu_pos = 2;
break;
}
mdelay(400);
}
// check if buttons were pushed
// middle button --> increase menu
mdelay(100);
menu_pos++;
if (menu_pos > 2) {menu_pos = 0;}
flag_redraw_menu = 0xFF;
} else {
// right button --> calculate new threshold value
mdelay(100);
adc_min = 255;
adc_max = 0;
if (value < adc_min) {adc_min = value;}
if (value > adc_max) {adc_max = value;}
if (value < adc_min) {adc_min = value;}
if (value > adc_max) {adc_max = value;}
if (value < adc_min) {adc_min = value;}
if (value > adc_max) {adc_max = value;}
if (value < adc_min) {adc_min = value;}
if (value > adc_max) {adc_max = value;}
if (value < adc_min) {adc_min = value;}
if (value > adc_max) {adc_max = value;}
// mean value
value = (adc_min >> 1) + (adc_max >> 1);
}
// update display depending on menu position
switch (menu_pos) {
case 0 :
lcdxy(13,1);
}
lcdxy(2,1);
if (value & kLineDigitalFrontLeft ) {lcdout('L'); }
else {lcdout(' ');}
if (value & kLineDigitalFrontMiddle) {lcdout('M'); }
else {lcdout(' ');}
if (value & kLineDigitalFrontRight ) {lcdout('R'); }
else {lcdout(' ');}
lcdxy(8,1);
if (value & kLineDigitalMiddleLeft ) {lcdout('L'); }
else {lcdout(' ');}
if (value & kLineDigitalMiddleRight) {lcdout('R'); }
else {lcdout(' ');}
mdelay(250);
}
break;
case 1 :
lcdxy( 0,1);
lcdxy( 6,1);
lcdxy(13,1);
mdelay(250);
}
break;
default:
lcdxy( 0,1);
lcdxy(13,1);
mdelay(250);
}
break;
}
}
}
}
//*********************************[main]***************************************
int main (void) {
init_tucbot(0xFF);
testLine();
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.
kLineSetThreshold
@ kLineSetThreshold
Definition: line.h:171
kButtonMiddle
@ kButtonMiddle
bit mask (0x08): middle button
Definition: buttons.h:35
kLineDigitalMiddleLeft
@ kLineDigitalMiddleLeft
bit mask (0x08): middle left line sensor
Definition: line.h:37
line_received
eLineSelectMask line_received(eLineSelectMask bitmask)
Indicates if new data for the selected data blocks were received.
line_request
void line_request(eLineSelectMask bitmask, eRequestType request)
Requests new data from the line sensors.
kLedOn
@ kLedOn
constant (0xFF): turn leds on
Definition: leds.h:63
kLedRight
@ kLedRight
bit mask (0x04): right led
Definition: leds.h:46
kLineSelectMiddle
@ kLineSelectMiddle
Definition: line.h:125
kLineGetMiddleRight
@ kLineGetMiddleRight
constant (5): middle right line sensor
Definition: line.h:153
kLineGetThreshold
@ kLineGetThreshold
constant (8): theshold value for converting to digital bitfield
Definition: line.h:159
kLineGetFrontMiddle
@ kLineGetFrontMiddle
constant (2): front middle line sensor
Definition: line.h:147
kButtonRight
@ kButtonRight
bit mask (0x10): right button
Definition: buttons.h:37
kLineGetFrontLeft
@ kLineGetFrontLeft
constant (1): front left line sensor
Definition: line.h:145
kLineDigitalMiddleRight
@ kLineDigitalMiddleRight
bit mask (0x10): middle right line sensor
Definition: line.h:39
kLineSelectDigital
@ kLineSelectDigital
Definition: line.h:128
line_get
uint8_t line_get(eLineGet select)
Returns the last stored version of the selected value.
kLineEnableAll
@ kLineEnableAll
bit mask (0x03): enable all line sensors
Definition: line.h:57
buttons_request
void buttons_request(eRequestType request)
Requests new data from the buttons.
kRequestContinuous
@ kRequestContinuous
constant (3): request continuous updates
Definition: update.h:37
kLineSetEnable
@ kLineSetEnable
constant (kLineGetEnable): bitfield of enabled line sensor groups
Definition: line.h:169
kLineDigitalFrontMiddle
@ kLineDigitalFrontMiddle
bit mask (0x02): front middle line sensor
Definition: line.h:33
kLedMiddle
@ kLedMiddle
bit mask (0x08): middle led
Definition: leds.h:44
kLedOff
@ kLedOff
constant (0x00): turn leds off
Definition: leds.h:61
uint16tostr
void uint16tostr(void *out, uint16_t number, uint8_t digits)
Converts an unsigned integer to a string and passes it to an output function.
lcdclr
void lcdclr(void)
Clears the display.
line_changed
eLineSelectMask line_changed(eLineSelectMask bitmask)
Indicates if new data changed the selected data blocks.
kLineSelectAll
@ kLineSelectAll
bit mask (0x0F): select all data blocks
Definition: line.h:135
lcdxy
void lcdxy(uint8_t x, uint8_t y)
Moves the cursor to a postion on the display.
kRequestSingle
@ kRequestSingle
constant (1): request a single update
Definition: update.h:33
kLineGetFrontRight
@ kLineGetFrontRight
constant (3): front right line sensor
Definition: line.h:149
kLineDigitalFrontLeft
@ kLineDigitalFrontLeft
bit mask (0x01): front left line sensor
Definition: line.h:31
lcdstr_p
void lcdstr_p(const char *send_data)
Writes a string located in the flash to the display.
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.
line_set
void line_set(eLineSet select, uint8_t value)
Sets the selected values of the line sensors.
kLineSelectEnable
@ kLineSelectEnable
Definition: line.h:131
kLineDigitalFrontRight
@ kLineDigitalFrontRight
bit mask (0x04): front right line sensor
Definition: line.h:35
kLineGetDigital
@ kLineGetDigital
constant (6): bitfield of all line sensor
Definition: line.h:155
kLineSelectFront
@ kLineSelectFront
Definition: line.h:122
kLineGetMiddleLeft
@ kLineGetMiddleLeft
constant (4): middle left line sensor
Definition: line.h:151