Go Down

Topic: 用光敏电阻(LDR)计算LED在一分钟内闪烁的次数 (Read 454 times) previous topic - next topic

janethooooo

大家好!请问我的程序应该怎么写,才能让LED闪烁的次数的展示出来呢?我已经试过了,但展示出来的总是6和0。
Code: [Select]
//#include <SevSeg.h>
const int LED_red = 12;
const int LED_blue = 13;
const int blue = A0;
const int red = A1;
int countRED = 0;
int countBLUE = 0;

void setup()
{
  pinMode (LED_red, OUTPUT);
  pinMode (LED_blue, OUTPUT);
 
  pinMode (red, INPUT);
  pinMode (blue, INPUT);
 
pinMode(2, OUTPUT); //a
pinMode(3, OUTPUT); //b
pinMode(4, OUTPUT); //c
pinMode(5, OUTPUT); //d
pinMode(6, OUTPUT); //e
pinMode(7, OUTPUT); //f
pinMode(8, OUTPUT); //g
Serial.begin(9600); // Monitor
}

void loop()
{
  digitalWrite(random(12,14),HIGH);
  delay(3000);
  digitalWrite (LED_blue, LOW);
  digitalWrite (LED_red, LOW);
  delay(1000);
 
  zero();
  countRED = map(countRED, 410, 640, 0, 9);
  countRED = analogRead(red);
  Serial.println(countRED);
  countBLUE = map(countBLUE, 410, 640, 0, 9);
  countBLUE = analogRead(blue);
  Serial.println(countBLUE);
 
  if(countRED==0 || countBLUE==0 ){zero();}
  if(countRED==1 || countBLUE==1 ){one();}
  if(countRED==2 || countBLUE==2 ){two();}
  if(countRED==3 || countBLUE==3){three();}
  if(countRED==4 || countBLUE==4 ){four();}
  if(countRED==5 || countBLUE==5){five();}
  if(countRED==6 || countBLUE==6){six();}
  if(countRED==7 || countBLUE==7){seven();}
  if(countRED==8 || countBLUE==8){eight();}
  if(countRED==9 || countBLUE==9){nine();}
}
void one(){
  digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
    digitalWrite(6, HIGH); 
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
    delay(2000);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
 
}

void two(){
  digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
  digitalWrite(7, HIGH);
    digitalWrite(8, LOW);
    delay(2000);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
}
void three(){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
  digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, LOW);
    delay(2000);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
}
void four(){
  digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    delay(2000);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
}
void five(){
    digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
  digitalWrite(6, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    delay(2000);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
}
void six(){
    digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    delay(2000);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
}
void seven(){
   digitalWrite(2, LOW);
   digitalWrite(3, LOW);
   digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
   digitalWrite(6, HIGH);
   digitalWrite(7, HIGH);
   digitalWrite(8, HIGH);
   delay(2000);
   digitalWrite(2, HIGH);
   digitalWrite(3, HIGH);
   digitalWrite(4, HIGH);
   digitalWrite(5, HIGH);
   digitalWrite(6, HIGH);
   digitalWrite(7, HIGH);
   digitalWrite(8, HIGH);
}

void eight(){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW); 
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
  delay(2000);
  digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
}
void nine(){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
  digitalWrite(6, HIGH);
    digitalWrite(7, LOW); 
    digitalWrite(8, LOW);
  delay(2000);
    digitalWrite(2, HIGH);
   digitalWrite(3, HIGH);
   digitalWrite(4, HIGH);
   digitalWrite(5, HIGH);
   digitalWrite(6, HIGH);
   digitalWrite(7, HIGH);
   digitalWrite(8, HIGH);
}
void zero(){
  digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
  digitalWrite(8, HIGH); 
  delay(2000);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
}




Go Up