LED eingebaut.

This commit is contained in:
neoraider 2007-04-19 00:12:03 +00:00
parent e7eeeb0d4e
commit 6252267743
4 changed files with 29 additions and 4 deletions

20
avr.cpp
View file

@ -19,13 +19,21 @@ int getButton() {
} }
void waitForButton(int i) { void waitForButton(int i) {
while(getButton() != CLAMP(0, i, 5)); if(i <= 0) while(getButton() == 0);
else while(getButton() != CLAMP(1, i, 5));
while(getButton() != 0); while(getButton() != 0);
} }
void beep(unsigned long freq) { void beep(unsigned long freq) {
const int prescalers[7] = {1, 8, 32, 64, 128, 256, 1024}; const int prescalers[7] = {1, 8, 32, 64, 128, 256, 1024};
if(freq == 0) {
beepOff();
return;
}
for(int i = 0; i < 7; i++) { for(int i = 0; i < 7; i++) {
if(F_CPU/freq/2/prescalers[i] <= 256) { if(F_CPU/freq/2/prescalers[i] <= 256) {
TCCR2 = (TCCR2&~0x07)|(i+1); TCCR2 = (TCCR2&~0x07)|(i+1);
@ -39,5 +47,13 @@ void beep(unsigned long freq) {
} }
void beepOff() { void beepOff() {
TCCR2 &= ~0x07; TCCR2 &= ~0x07;
}
void ledOn() {
PORTA &= ~0x20;
}
void ledOff() {
PORTA |= 0x20;
} }

3
avr.h
View file

@ -10,4 +10,7 @@ void waitForButton(int i);
void beep(unsigned long freq); void beep(unsigned long freq);
void beepOff(); void beepOff();
void ledOn();
void ledOff();
#endif #endif

View file

@ -8,7 +8,7 @@
void initHardware() { void initHardware() {
DDRA = 0x00; DDRA = 0x20;
PORTA = 0xFF; PORTA = 0xFF;
DDRB = 0xFF; DDRB = 0xFF;

View file

@ -48,10 +48,16 @@ int main() {
Srf10 *srf10Last = srf10Left; Srf10 *srf10Last = srf10Left;
do { do {
lineSensorArray->update(); lineSensorArray->update();
} while(!lineSensorArray->calibrate()); } while(!lineSensorArray->calibrate());
ledOn();
waitForButton(0);
ledOff();
sleep(4000);
navigation->setSpeed(DEFAULT_SPEED); navigation->setSpeed(DEFAULT_SPEED);
while(true) { while(true) {