online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <stdio.h> #include <stdint.h> uint32_t states[4] = {0b01, 0b11, 0b00, 0b10}; uint32_t A = 0, B = 0, AB_old = 0, AB_new = 0; int32_t pos = 0; void encoder_main_loop() { AB_new = (A ? 0b10 : 0x00) | ( B ? 0b01 : 0x00); if ( AB_new == AB_old ) return; pos += states[AB_old] == AB_new ? 1 : -1; printf("A:%u, B:%u, AB_new:%u, AB_old:%u, pos:%i \n",A,B,AB_new,AB_old,pos); AB_old = AB_new; } int main() { uint32_t i, p, pulses = 100; printf("--- making %u pulses forward --------------\n", pulses); for ( i = pulses, p = 0; i--; ) { // Encoder pulses generator, direction = Clockwise // A _____|`````|_____|`````|_____|`````|__ // B __|`````|_____|`````|_____|`````|_____ switch (p) { case 0: { B = !B; break; } case 1: { A = !A; break; } case 2: { B = !B; break; } case 3: { A = !A; break; } } p = (++p) & 0b11; // encoder counter encoder_main_loop(); } printf("--- making %u pulses back --------------\n", pulses); for ( i = pulses, p = 0; i--; ) { // Encoder pulses generator, direction = Counter-Clockwise // A __|`````|_____|`````|_____|`````|_____ // B _____|`````|_____|`````|_____|`````|__ switch (p) { case 0: { A = !A; break; } case 1: { B = !B; break; } case 2: { A = !A; break; } case 3: { B = !B; break; } } p = (++p) & 0b11; // encoder counter encoder_main_loop(); } return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue