Created
April 16, 2016 06:18
-
-
Save kinoshita-lab/e50fbb6385f9f6b499d3a143b5552c38 to your computer and use it in GitHub Desktop.
20160416
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int currentStep = 0; | |
constexpr int NUM_STEP = 16; | |
// d3 d4 d5 = 74hc138 in a b c | |
const uint8_t LED_BIT_TABLE[NUM_STEP][3] = { | |
{0, 0, 0}, | |
{1, 0, 0}, | |
{0, 1, 0}, | |
{1, 1, 0}, | |
{0, 0, 1}, | |
{1, 0, 1}, | |
{0, 1, 1}, | |
{1, 1, 1}, | |
{0, 0, 0}, | |
{1, 0, 0}, | |
{0, 1, 0}, | |
{1, 1, 0}, | |
{0, 0, 1}, | |
{1, 0, 1}, | |
{0, 1, 1}, | |
{1, 1, 1}, | |
}; | |
// d7 lo 8bits | |
// d6 hi 8bits | |
void step() | |
{ | |
// turn LEDs | |
digitalWrite(3, LED_BIT_TABLE[currentStep][0]); | |
digitalWrite(4, LED_BIT_TABLE[currentStep][1]); | |
digitalWrite(5, LED_BIT_TABLE[currentStep][2]); | |
if (currentStep < 8) { | |
digitalWrite(7, LOW); | |
digitalWrite(6, HIGH); | |
} else { | |
digitalWrite(7, HIGH); | |
digitalWrite(6, LOW); | |
} | |
// read analog value | |
digitalWrite(8, LED_BIT_TABLE[currentStep][0]); | |
digitalWrite(9, LED_BIT_TABLE[currentStep][1]); | |
digitalWrite(10, LED_BIT_TABLE[currentStep][2]); | |
const auto pin = currentStep < 8 ? 0 : 4; | |
const auto analogValue = analogRead(pin); | |
analogWrite(11, analogValue >> 2); | |
Serial.println(analogValue); | |
currentStep++; | |
if (currentStep == NUM_STEP) { | |
currentStep = 0; | |
} | |
} | |
void setup() { | |
pinMode(3, OUTPUT); | |
pinMode(4, OUTPUT); | |
pinMode(5, OUTPUT); | |
pinMode(6, OUTPUT); | |
pinMode(7, OUTPUT); | |
pinMode(8, OUTPUT); | |
pinMode(9, OUTPUT); | |
pinMode(10, OUTPUT); | |
pinMode(11, OUTPUT); | |
Serial.begin(115200); | |
attachInterrupt(0, step, RISING); | |
step(); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment