Create a gist now

Instantly share code, notes, and snippets.

@takumus /28BYJ-48.c Secret
Last active Sep 13, 2016

What would you like to do?
#include <Arduino.h>
const int IN1 = 9;
const int IN2 = 10;
const int IN3 = 11;
const int IN4 = 12;
int d_hs[8] = {
B1000,
B1100,
B0100,
B0110,
B0010,
B0011,
B0001,
B1001
};
int i = 0;
void step(int d);
void setup()
{
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop()
{
step(1);
delayMicroseconds(900);
}
void step(int d)
{
i += d;
if(i > 7) i = 0;
if(i < 0) i = 7;
byte b = d_hs[i];
digitalWrite(IN1, bitRead(b, 0));
digitalWrite(IN2, bitRead(b, 1));
digitalWrite(IN3, bitRead(b, 2));
digitalWrite(IN4, bitRead(b, 3));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment