Jörg Sturm
/
Vorlage
Encoder
main.cpp
- Committer:
- JoergSturm
- Date:
- 2020-02-20
- Revision:
- 0:46dbd1b71de5
File content as of revision 0:46dbd1b71de5:
#include "mbed.h" DigitalOut myled(LED1); DigitalOut Center(PA_9); DigitalIn Port0(PA_8); DigitalIn Port1(PA_10); PortOut C(PortC,0xFF); InterruptIn irqA(PA_1); InterruptIn irq0(PA_8); InterruptIn irq1(PA_10); int z=0,Zustand=0,Zustandalt=0; void isr(void) { myled=!myled; } void isrEnc(void) { Zustandalt=Zustand; if (Port0==0 && Port1==0) Zustand=0; if (Port0==1 && Port1==0) Zustand=1; if (Port0==1 && Port1==1) Zustand=2; if (Port0==0 && Port1==1) Zustand=3; if (Zustandalt==3 && Zustand==0) z++; if (Zustandalt==0 && Zustand == 3) z--; C=(z<<2)+Zustand; } int main() { Center=1; // Port0.mode(PullDown); // Port1.mode(PullDown); irqA.rise(&isr); irqA.mode(PullDown); irq0.rise(&isrEnc); irq0.fall(&isrEnc); irq0.mode(PullDown); irq1.rise(&isrEnc); irq1.fall(&isrEnc); irq1.mode(PullDown); RCC->AHBENR|=0b100; GPIOC->MODER=0x5555; //GPIOC->ODR=0x55; C=0; while(1) { /* myled = 1; // LED is ON wait(0.2); // 200 ms myled = 0; // LED is OFF wait(1.0); // 1 sec C=0; */ } }