cyclic.c
/*******************************************************************************
* examples/cyclic.c *
* ================= *
* *
* Version: 1.0.6 *
* 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 testCyclic_beds(void);
void testCyclic_beeper(void);
void testCyclic(void);
int main(void);
//*********************************[testCyclic_leds]****************************
void testCyclic_leds(void) {
static uint8_t state = 0;
state = !state;
}
//*********************************[testCyclic_beeper]**************************
void testCyclic_beeper(void) {
static uint8_t nr = 0;
static uint16_t frequ;
#define MUSIC_NOTE_A_L 440
#define MUSIC_NOTE_H_L 494
#define MUSIC_NOTE_C 523
#define MUSIC_NOTE_D 587
#define MUSIC_NOTE_E 659
#define MUSIC_NOTE_F 698
#define MUSIC_NOTE_G 783
#define MUSIC_NOTE_A 880
#define MUSIC_NOTE_H 988
#define MUSIC_NOTE_C_1 1047
#define MUSIC_NOTE_D_1 1175
#define MUSIC_NOTE_E_1 1319
#define MUSIC_NOTE_F_1 1397
#define MUSIC_NOTE_G_1 1568
#define MUSIC_NOTE_A_1 1760
#define MUSIC_NOTE_H_1 1976
frequ = 0;
nr++;
if (nr >= 160) {nr = 0;}
if (nr > 128) {
return;
}
if (nr < 65) {
switch (nr & 31) {
// tact 1 & 5
case 1: frequ = MUSIC_NOTE_E_1; break;
case 3: frequ = MUSIC_NOTE_E_1; break;
case 5: frequ = MUSIC_NOTE_F_1; break;
case 7: frequ = MUSIC_NOTE_G_1; break;
// tact 2 & 6
case 9: frequ = MUSIC_NOTE_G_1; break;
case 11: frequ = MUSIC_NOTE_F_1; break;
case 13: frequ = MUSIC_NOTE_E_1; break;
case 15: frequ = MUSIC_NOTE_D_1; break;
// tact 3 & 7
case 17: frequ = MUSIC_NOTE_C_1; break;
case 19: frequ = MUSIC_NOTE_C_1; break;
case 21: frequ = MUSIC_NOTE_D_1; break;
case 23: frequ = MUSIC_NOTE_E_1; break;
// tact 4 & 8
case 26: frequ = MUSIC_NOTE_E_1; break;
case 27: frequ = MUSIC_NOTE_D_1; break;
case 31: frequ = MUSIC_NOTE_D_1; break;
}
} else {
switch (nr) {
// tact 9
case 65: frequ = MUSIC_NOTE_D_1; break;
case 67: frequ = MUSIC_NOTE_D_1; break;
case 69: frequ = MUSIC_NOTE_E_1; break;
case 71: frequ = MUSIC_NOTE_C_1; break;
// tact 10
case 73: frequ = MUSIC_NOTE_D_1; break;
case 74: frequ = MUSIC_NOTE_E_1; break;
case 75: frequ = MUSIC_NOTE_F_1; break;
case 77: frequ = MUSIC_NOTE_E_1; break;
case 79: frequ = MUSIC_NOTE_C_1; break;
// tact 11
case 81: frequ = MUSIC_NOTE_D_1; break;
case 82: frequ = MUSIC_NOTE_E_1; break;
case 83: frequ = MUSIC_NOTE_F_1; break;
case 85: frequ = MUSIC_NOTE_E_1; break;
case 87: frequ = MUSIC_NOTE_F_1; break;
// tact 12
case 89: frequ = MUSIC_NOTE_C_1; break;
case 91: frequ = MUSIC_NOTE_D_1; break;
case 93: frequ = MUSIC_NOTE_G ; break;
case 95: frequ = MUSIC_NOTE_E_1; break;
// tact 13
case 97: frequ = MUSIC_NOTE_E_1; break;
case 99: frequ = MUSIC_NOTE_E_1; break;
case 101: frequ = MUSIC_NOTE_F_1; break;
case 103: frequ = MUSIC_NOTE_G_1; break;
// tact 14
case 105: frequ = MUSIC_NOTE_G_1; break;
case 107: frequ = MUSIC_NOTE_F_1; break;
case 109: frequ = MUSIC_NOTE_E_1; break;
case 111: frequ = MUSIC_NOTE_D_1; break;
// tact 15
case 113: frequ = MUSIC_NOTE_C_1; break;
case 115: frequ = MUSIC_NOTE_C_1; break;
case 117: frequ = MUSIC_NOTE_D_1; break;
case 119: frequ = MUSIC_NOTE_E_1; break;
// tact 16
case 121: frequ = MUSIC_NOTE_D_1; break;
case 124: frequ = MUSIC_NOTE_C_1; break;
case 125: frequ = MUSIC_NOTE_C_1; break;
}
}
if ( frequ ) {
mdelay(50);
beeper_set(frequ);
}
}
//*********************************[testCyclic]*********************************
void testCyclic(void) {
uint8_t pos = 0;
static uint8_t id = 0;
lcdclr();
lcdstr_p(PSTR("Cyclic call" ));
lcdxy(0,1);
lcdstr_p(PSTR("................"));
while (1) {
mdelay(100);
if (id == 0) {
id = time_cycleAdd(testCyclic_beeper, 12);
lcdxy(15,0);
lcdout('B');
} else {
id = 0;
lcdxy(15,0);
lcdout(' ');
}
mdelay(400);
}
if (pos < 15) {
lcdxy(pos,1);
lcdout(' ');
lcdout('x');
pos++;
} else {
lcdxy(15,1);
lcdout(' ');
lcdxy( 0,1);
lcdout('x');
pos = 0;
}
mdelay(200);
}
}
//*********************************[main]***************************************
int main (void) {
init_tucbot(0xFF);
time_cycleAdd(testCyclic_leds, 20);
testCyclic();
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.
beeper_off
void beeper_off(void)
Turns the beeper off.
kLedOn
@ kLedOn
constant (0xFF): turn leds on
Definition: leds.h:63
kLedRight
@ kLedRight
bit mask (0x04): right led
Definition: leds.h:46
kButtonRight
@ kButtonRight
bit mask (0x10): right button
Definition: buttons.h:37
buttons_request
void buttons_request(eRequestType request)
Requests new data from the buttons.
time_cycleClear
void time_cycleClear(uint8_t id)
Removes a function from the cyclic called functions.
beeper_set
void beeper_set(uint16_t Hz)
Sets the frequency of the beeper.
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
lcdclr
void lcdclr(void)
Clears the display.
time_cycleAdd
uint8_t time_cycleAdd(void *function, uint8_t interval)
Adds a function to the cyclic called functions.
lcdxy
void lcdxy(uint8_t x, uint8_t y)
Moves the cursor to a postion on the display.
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.