Skip to content

Instantly share code, notes, and snippets.

@takumus
Last active September 13, 2016 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takumus/fe2356c0c250be90f0cc05bc1904a141 to your computer and use it in GitHub Desktop.
Save takumus/fe2356c0c250be90f0cc05bc1904a141 to your computer and use it in GitHub Desktop.
#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