01-23-2018, 11:47 PM
To bi trebalo biti ovako:
samo nešto sam promašio, jer mi odmah zakuca u while petlju i svijetli mi ledica što sam ja dodao da znam kad je taster aktivan ali ne šalje podatke (ne svijetli mi TX lampica)?
Code:
int LED = 12;
int taster1 = 8;
int taster2 = 9;
unsigned char taster1test = 0;
unsigned char taster2test = 0;
boolean flag1 = false;
void setup() {
pinMode(LED, OUTPUT);
pinMode(taster1, INPUT);
pinMode(taster2, INPUT);
Serial.begin(9600);
// initialize Timer1
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 62535;//49536;//62437;//34286; // preload timer 65536-16MHz/256/2Hz
TCCR1B |= (0 << CS10 ) | (0 << CS11) | (1 << CS12); //256
TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt
interrupts(); // enable all interrupts
}
ISR(TIMER1_OVF_vect) // interrupt service routine that wraps a user defined function supplied by attachInterrupt
{
TCNT1 = 62535; // preload timer
if(digitalRead(8) == HIGH){
taster1test++;
if(taster1test > 3){
flag1 = true;
digitalWrite(LED, HIGH);
}
}
else{
taster1test = 0;
}
}
void loop() {
while(1){
if(flag1){
flag1 = false;
Serial.println(1111);
}
}
}