Last active
March 5, 2017 14:40
-
-
Save kamiyaowl/509ab12558636e9b4db8 to your computer and use it in GitHub Desktop.
VFD(IV-18)を光らせる
This file contains 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
const uint8_t sw_out = 9; | |
uint16_t target_value = 1023; | |
const uint8_t segments_pin[] = {0, 1, 2, 3, 4, 5, 6}; | |
const uint8_t orders_pin[] = {A4, A3, A2, A1, 13, 12, 11, 10}; | |
const uint8_t segments_count = 7; | |
const uint8_t orders_count = 8; | |
const uint8_t segment_data[] = { | |
0b11111100,//0 | |
0b01100000,//1 | |
0b11011010,//2 | |
0b11110010,//3 | |
0b01100110,//4 | |
0b10110110,//5 | |
0b10111110,//6 | |
0b11100100,//7 | |
0b11111110,//8 | |
0b11110110,//9 | |
0b11101110,//A | |
0b00111110,//b | |
0b10011100,//C | |
0b01111010,//d | |
0b10011110,//E | |
0b10001110,//F | |
}; | |
uint8_t show_num[] = {0,1,2,3,4,5,6,7}; | |
void setup() { | |
pinMode(sw_out,OUTPUT); | |
for(uint8_t i = 0 ; i < segments_count ; ++i){ | |
pinMode(segments_pin[i], OUTPUT); | |
digitalWrite(segments_pin[i], LOW); | |
} | |
for(uint8_t i = 0 ; i < orders_count ; ++i){ | |
pinMode(orders_pin[i], OUTPUT); | |
digitalWrite(orders_pin[i], LOW); | |
} | |
} | |
void loop() { | |
/* voltage boost */ | |
uint16_t data = analogRead(A0); | |
uint8_t duty = (target_value < data) ? 0 : ((target_value - data) >> 2); | |
analogWrite(sw_out, duty); | |
/* VFD show */ | |
for(uint8_t i = 0 ; i < orders_count ; ++i){ | |
digitalWrite(orders_pin[i], LOW); | |
for(uint8_t j = 0 ; j < segments_count ; ++j){ | |
digitalWrite(segments_pin[j],(segment_data[show_num[i]] << j) & 0x80); | |
} | |
digitalWrite(orders_pin[i], HIGH); | |
delayMicroseconds(50000);//deadtime | |
digitalWrite(orders_pin[i], LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment