Create a gist now

Instantly share code, notes, and snippets.

@takumus /suteppa_demo_01.cpp Secret
Last active Sep 24, 2016

What would you like to do?
#include <Arduino.h>
#include "Suteppa.h"
#define IN1 9
#define IN2 10
#define IN3 11
#define IN4 12
Suteppa s;
void step(int d)
{
static const int hs[8] = {0b1000,0b1100,0b0100,0b0110,0b0010,0b0011,0b0001,0b1001};
static int i;
i += d;
if(i > 7) i = 0;
if(i < 0) i = 7;
byte b = hs[i];
digitalWrite(IN1, bitRead(b, 0));
digitalWrite(IN2, bitRead(b, 1));
digitalWrite(IN3, bitRead(b, 2));
digitalWrite(IN4, bitRead(b, 3));
}
void setup()
{
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
//一回転のステップ数, ステップ用関数
s.init(4096, step);
//100ステップを加減速に使い, 開始速度は2000us
s.beginSmooth(100, 2000);
//通常速度は700us
s.setSpeed(700);
}
void loop()
{
//相対角度で、4096ステップ回転
s.rotate(Suteppa::RELATIVE, 4096);
//待つ
delay(1000);
//絶対角度で、0ステップへ戻る
s.rotate(Suteppa::ABSOLUTE, 0);
//待つ
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment