//アナログシグナル
int sensorPin = 18 ; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
//表示LEDピン
int led[] ={14,12,11,10,9,8,7,6,5,4};//45678910111214
//回転数 境界数値 X100
int rpm[] ={10,15,20,25,30,35,40,45,50,60};//45678910111214
int real_rpm=0;
int real_rpm_old=0;
// the setup routine runs once when you press reset:
int buttonState = 0;
unsigned long time0;
unsigned long time1;
unsigned long time;
void setup() {
// initialize the digital pin as an output.
for (int i=0; i <= 9; i++){
pinMode(led[i], OUTPUT);
}
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, LOW);
open_led() ;
// Serial.begin(9600);
}
void open_led() {
for (int i=0; i <= 9; i++){
digitalWrite(led[i], HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led[i], LOW); // turn the LED on (HIGH is the voltage level)
//delay(100); // wait for a second
}
for (int i=9; i >= 0; i--){
digitalWrite(led[i], HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led[i], LOW); // turn the LED on (HIGH is the voltage level)
//delay(100); // wait for a second
}
delay(100);
for (int i=0; i <= 9; i++){
digitalWrite(led[i], HIGH); // turn the LED on (HIGH is the voltage level)
delay(100);
}
delay(500);
for (int i=0; i <= 9; i++){
digitalWrite(led[i], LOW); // turn the LED on (HIGH is the voltage level)
delay(100);
}
rpm_set( real_rpm);
real_rpm_old=real_rpm;
}
void rpm_set(int real_rpm) {
//count real_rpm
int led_no=10;
for (int i=9; i >=0; i--){
if (rpm[i]>real_rpm){
led_no=i;
}
}
led_on(led_no);
}
void led_on(int ii) {
for (int i=0; i <= ii-1; i++){
digitalWrite(led[i], HIGH); // turn the LED on (HIGH is the voltage level)
// delay(100); // wait for a second
}
for (int i=ii; i <= 9; i++){
digitalWrite(led[i], LOW); // turn the LED off by making the voltage LOW
// delay(100);
} // wait for a second
}
}
void open_led() {
for (int i = 0; i <= 9; i++) {
digitalWrite(led[i], tipe_set_LOW );
}
for (int i = 0; i <= 9; i++) {
digitalWrite(led[i], tipe_set_HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led[i], tipe_set_LOW ); // turn the LED on (HIGH is the voltage level)
//delay(100); // wait for a second
}
for (int i = 9; i >= 0; i--) {
digitalWrite(led[i], tipe_set_HIGH ); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led[i], tipe_set_LOW ); // turn the LED on (HIGH is the voltage level)
// delay(100); // wait for a second
}
delay(100);
for (int i = 0; i <= 9; i++) {
digitalWrite(led[i], tipe_set_LOW); // turn the LED on (HIGH is the voltage level)
delay(100);
}
// delay(500);
for (int i = 0; i <= 9; i++) {
digitalWrite(led[i], tipe_set_HIGH); // turn the LED on (HIGH is the voltage level)
delay(100);
}
for (int i = 9; i >= 0; i--) {
digitalWrite(led[i], tipe_set_LOW); // turn the LED on (HIGH is the voltage level)
delay(100);
}
}
int v = 0;
void loop() {
time = (millis() % sokuteijikan);
int count = 0;
buttonState = digitalRead(sensorPin);
if (( buttonState == tipe_set_LOW) * (v == 1)) {
v = 0;
//count++;
for (int i = 0; i <= (cc - 1); i++) {
timecount[i] ++;
}
count = 1;
}
if (( buttonState == tipe_set_HIGH) * (v == 0)) {
v = 1;
}
if ( ( time / bunkatujikan) != old_time_count) {
sokudo[time / bunkatujikan] = timecount[ time / bunkatujikan] * one_p_mm * 36 / sokuteijikan ; //km/h
timecount[ time / bunkatujikan] = 0;
}
old_time_count = time / bunkatujikan;
int speed_he = 0;
for (int i = 0; i <= ( cc - 1); i++) {
speed_he = speed_he + sokudo[i];
}
speed_he = speed_he / cc;
led_on(speed_he / 160);
}
void led_on(int ii) {
if (ii > 11) {
ii = 10;
}
for (int i = 0; i <= ii - 1; i++) {
digitalWrite(led[i], tipe_set_HIGH); // turn the LED on (HIGH is the voltage level)
// delay(100); // wait for a second
}
if (ii <= 9) {
for (int i = ii; i <= 9; i++) {
digitalWrite(led[i], tipe_set_LOW); // turn the LED off by making the voltage LOW
// delay(100);
} // wait for a second
// these constants won't change:
const int inputPin = 17; // the pin that the potentiometer is attached to
const int ledCount = 10; // the number of LEDs in the bar graph
int ledPins[] = {
4, 5, 6, 7,8,9,10,11,12,14 }; // an array of pin numbers to which LEDs are attached
int sig_old=0;
int sig_now=0;
int sig_chenge=0;
int sig_count=0;
int check_count=2000;
void setup() {
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < x) {
digitalWrite(ledPins[thisLed], LOW);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], HIGH);
}
}
}
スピードメータ 02
// these constants won't change:
const int inputPin = 17; // the pin that the potentiometer is attached to
const int ledCount = 10; // the number of LEDs in the bar graph
int ledPins[] = {
4, 5, 6, 7, 8, 9, 10, 11, 12, 14
}; // an array of pin numbers to which LEDs are attached
int sig_old = 0;
int sig_now = 0;
int sig_chenge = 0;
int sig_count = 0;
int check_count = 2000;
long vv = 0;
long v_count = 0;
long V = 1;
unsigned long v_time = 150000;
unsigned long v_time0 = 0;
unsigned long time;
void setup() {
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
pinMode( inputPin, INPUT);
pinMode(13, OUTPUT);
time = micros();
v_time0 = time ;
// Serial.begin(9600);
}
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < x) {
digitalWrite(ledPins[thisLed], LOW);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], HIGH);
}
}
}