Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Encoders.cpp
- Committer:
- Thijsjeee
- Date:
- 2018-09-25
- Revision:
- 0:fb2b540167a8
File content as of revision 0:fb2b540167a8:
#include "mbed.h"
#include <math.h>
DigitalOut Led1(D5);
DigitalOut Led2(D4);
DigitalIn B(D2);
DigitalIn A(D3);
Ticker check;
Ticker printer;
volatile int prev_A;
volatile int prev_B;
int state = 0;
void Printer()
{
printf("%i\r\n",state);
}
void Checker ()
{
if (prev_A == 1)
{
if(A == 0)
{
++state;
}
}
if (prev_A == 0)
{
if(A == 1)
{
++state;
}
}
prev_A = A;
if (prev_B == 1)
{
if(B == 0)
{
++state;
}
}
if (prev_B == 0)
{
if(B == 1)
{
++state;
}
}
prev_B = B;
}
main()
{
printer.attach(Printer, 0.1);
check.attach(Checker, 1e-6);
prev_A = A;
prev_B = B;
while(true)
{
}
}