
Har någon nåt bra tips på en kod som försätter UNO i strömsnålt viloläge efter en viss tid?
Och kan startas upp med en eller två knappar.

Mvh U
Förstår inte varför det är exotiskt. Han vill ju hålla reda på rotationsriktningen. Det betyder väl att han måste ta in både A och B signalen på varsin pinne.lillahuset skrev:Min första tanke är: Varför behöver du två interrupt till en rotary encoder? Låter ganska exotiskt.
Min andra tanke är: Nog för att Atmega 328 är en halvantik åttabittare men nog bord den ha fler än två externa interrupt. Och det har den, pin change på 23 I/O-pinnar.
Och det där "more complicated" kanske man skall passa sig för i detta fallet.The processor at the heart of any Arduino has two different kinds of interrupts: “external”, and “pin change”. There are only two external interrupt pins on the ATmega168/328 (ie, in the Arduino Uno/Nano/Duemilanove), INT0 and INT1, and they are mapped to Arduino pins 2 and 3.
On the other hand the pin change interrupts can be enabled on many more pins. For ATmega168/328-based Arduinos, they can be enabled on any or all 20 of the Arduino's signal pins; on the ATmega-based Arduinos they can be enabled on 24 pins.
Furthermore, the pin change interrupts are grouped into 3 “port”s on the MCU, so there are only 3 interrupt vectors (subroutines) for the entire body of pins. This makes the job of resolving the action on a single interrupt even more complicated.
Kod: Markera allt
Vector No. Program Address Source Interrupt Definition
1 0x0000 RESET External pin, power-on reset, brown-out reset and watchdog system reset
2 0x0002 INT0 External interrupt request 0
3 0x0004 INT1 External interrupt request 1
4 0x0006 PCINT0 Pin change interrupt request 0
5 0x0008 PCINT1 Pin change interrupt request 1
6 0x000A PCINT2 Pin change interrupt request 2
7 0x000C WDT Watchdog time-out interrupt
8 0x000E TIMER2 COMPA Timer/Counter2 compare match A
9 0x0010 TIMER2 COMPB Timer/Counter2 compare match B
10 0x0012 TIMER2 OVF Timer/Counter2 overflow
11 0x0014 TIMER1 CAPT Timer/Counter1 capture event
12 0x0016 TIMER1 COMPA Timer/Counter1 compare match A
13 0x0018 TIMER1 COMPB Timer/Counter1 compare match B
14 0x001A TIMER1 OVF Timer/Counter1 overflow
15 0x001C TIMER0 COMPA Timer/Counter0 compare match A
16 0x001E TIMER0 COMPB Timer/Counter0 compare match B
17 0x0020 TIMER0 OVF Timer/Counter0 overflow
18 0x0022 SPI, STC SPI serial transfer complete
19 0x0024 USART, RX USART Rx complete
20 0x0026 USART, UDRE USART, data register empty
21 0x0028 USART, TX USART, Tx complete
22 0x002A ADC ADC conversion complete
23 0x002C EE READY EEPROM ready
24 0x002E ANALOG COMP Analog comparator
25 0x0030 TWI 2-wire serial interface
26 0x0032 SPM READY Store program memory ready
Kod: Markera allt
// EnableInterrupt Simple example sketch. Demonstrates operation on a single pin of your choice.
// See https://github.com/GreyGnome/EnableInterrupt and the README.md for more information.
#include <EnableInterrupt.h>
#define ARDUINOPIN 7
volatile uint16_t interruptCount=0; // The count will go back to 0 after hitting 65535.
void interruptFunction() {
interruptCount++;
}
void setup() {
Serial.begin(115200);
pinMode(ARDUINOPIN, INPUT_PULLUP); // See http://arduino.cc/en/Tutorial/DigitalPins
enableInterrupt(ARDUINOPIN, interruptFunction, CHANGE);
}
// In the loop we just display interruptCount. The value is updated by the interrupt routine.
void loop() {
Serial.println("---------------------------------------");
delay(1000);
Serial.print("Pin was interrupted: ");
Serial.print(interruptCount, DEC);
Serial.println(" times so far.");
}