I am writing multithreading for Arduino, and for this you need to remove all delay(); . I replace these with millis(); , but this all works only once, although the cycle - the delay is correct, but it works once. Why is that?
Here is the code:
unsigned long previousMillis = 0; const long interval = 1000; int main() { //init(); while (1) { led13_ne(); } } void led13_ne() { DDRB |= B10000000; init(); unsigned long currentMillis = millis(); byte port13read = 0; if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; port13read = bitRead(PORTB, 8); if (port13read == 0) { PORTB |= B10000000; //port13read = 1; } else { PORTB &= ~B10000000; //port13read = 0; } } }
init();in the cycle why ? - Fat-ZerbitRead(PORTB, 8);- how do you read the ninth bit of a byte? - Fat-Zerinit();formillis();. - Super_Puper_Userinit ()in a loop ? andbitRead(PORTB, 8);- trying to return the ninth bit of the eight-bit value, it is clear that it will always be zero ... - Fat-Zer