User:Birgit bachler/BBB/rescue
< User:Birgit bachler | BBB
Revision as of 14:43, 17 December 2010 by Birgit bachler (talk | contribs) (Created page with " == phone_cont.pde == <source lang="C"> #include <avr/io.h> #include <avr/interrupt.h> #define gabelPin 4 #define klingelEn 7 #define klingelA 5 #define klingelB 6 #define kli...")
phone_cont.pde
#include <avr/io.h>
#include <avr/interrupt.h>
#define gabelPin 4
#define klingelEn 7
#define klingelA 5
#define klingelB 6
#define klingelPeriod 2500 //1250
void setup(void){
pinMode(gabelPin, INPUT);
digitalWrite(gabelPin, HIGH);
pinMode(klingelEn, OUTPUT);
pinMode(klingelA, OUTPUT);
pinMode(klingelB, OUTPUT);
sei();
TCCR1B = (_BV(CS12)); //timer at Fcpu/256
Serial.begin(115200);
}
void scheduleTimerInterrupt(void){
OCR1A = (unsigned int)TCNT1 + (unsigned int)klingelPeriod;
}
void startKlingel(void){
scheduleTimerInterrupt();
TIFR1 |= _BV(OCF1A);
TIMSK1 |= _BV(OCIE1A);
digitalWrite(klingelEn, HIGH);
digitalWrite(klingelA, HIGH);
digitalWrite(klingelB, LOW);
}
void stopKlingel(void){
TIMSK1 &= ~_BV(OCIE1A);
digitalWrite(klingelEn, LOW);
}
ISR(TIMER1_COMPA_vect){
PORTD ^= (_BV(5) | _BV(6));
scheduleTimerInterrupt();
}
int gabel = 0;
void loop(void){
int g;
if (Serial.available()){
switch (Serial.read()){
case 75: //K
startKlingel();
break;
case 107: //k
stopKlingel();
break;
case 114: //r
g = digitalRead(gabelPin);
if(g){
Serial.write("g\n");
}
else {
Serial.write("G\n");
}
break;
}
}
}