久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2551|回復: 1
打印 上一主題 下一主題
收起左側

定時開關計數器

[復制鏈接]
跳轉到指定樓層
樓主
ID:118080 發表于 2016-5-8 06:07 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
400黑幣
這是小弟的代碼
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
int runTimer = 1;
int runFor = 50; // time in seconds
int buzzerPin = 13;
int relayPin=4;
int data = 0;

const int switchPin = 5;
int hits = 0;
int switchState = 0;
int prevSwitchState = 0;


const int switchPin1 = 6;
int hits1 = 0;
int switchState1 = 0;
int prevSwitchState1 = 0;


void setup() {
{

   pinMode(buzzerPin, OUTPUT);
   pinMode(relayPin,OUTPUT);
   lcd.begin(16, 0);
}
{
   lcd.begin(16, 2);
   pinMode(switchPin,INPUT);



  pinMode(switchPin1,INPUT);

}
}

void loop() {

   switchState = digitalRead(switchPin);

  if (switchState != prevSwitchState) {
    if (switchState == LOW) {
      hits = hits + 1;
      lcd.clear();
      lcd.setCursor(0, 1);
      lcd.print("Hits:");
      lcd.setCursor(7, 1);
      lcd.print(hits);
      lcd.setCursor(11, 1);
      lcd.print(hits1);
      delay(90);
    }
  }
   prevSwitchState = switchState;


   switchState1 = digitalRead(switchPin1);

  if (switchState1 != prevSwitchState1) {
    if (switchState1 == LOW) {
      hits1 = hits1 + 1;
      lcd.clear();
      lcd.setCursor(0, 1);
      lcd.print("Hits:");
      lcd.setCursor(11, 1);
      lcd.print(hits1);
      lcd.setCursor(7, 1);
      lcd.print(hits);
      delay(90);
    }
  }
  prevSwitchState1 = switchState1;

   if(runTimer == 1){
      digitalWrite(relayPin,LOW); // relay is OFF during countdown

      lcd.clear();
      lcd.print("TIMER=");

      lcd.setCursor(0, 1);
      lcd.print("Hits:");
      lcd.setCursor(7, 1);
      lcd.print(hits);
      lcd.setCursor(11, 1);
      lcd.print(hits1)
      //Start timer
      ;timer();
   }
   runTimer = 0;
   lcd.noDisplay();
   delay(250);
   for(int duration = 0; duration < 100; duration ++){
      digitalWrite(buzzerPin, HIGH);
      delayMicroseconds(500);
      digitalWrite(buzzerPin, LOW);
      delayMicroseconds(500);
   }
   lcd.display();
   delay(250);
}

void timer() {
   for(int timer = runFor;timer > 0; --timer){
   if(timer >= 10) {
      lcd.setCursor(6,0);
   } else {   
      lcd.setCursor(6,0);
      lcd.print("0");
      lcd.setCursor(7,0);
   }
   lcd.print(timer);
   lcd.print(" SECOND!");
   delay(1000);
   }
   lcd.setCursor(1,1);
   lcd.clear();
   lcd.print(" TIMER OUT!");

      lcd.setCursor(0, 1);
      lcd.print("Hits:");
      lcd.setCursor(7, 1);
      lcd.print(hits);
      lcd.setCursor(11, 1);
      lcd.print(hits1);
}

當我用Arduino UNO 測試時,計時器工作但是開關計計數不工作。。請大神指點

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久精品中文 | 亚洲欧美日韩系列 | 国产亚洲精品久久久久久牛牛 | 精品一区二区在线观看 | 蜜桃臀av一区二区三区 | 欧美一级特黄aaa大片在线观看 | 午夜精品一区二区三区在线视频 | 精品久久久久久久 | 久久成人精品 | 色综合天天天天做夜夜夜夜做 | 日本精品国产 | 欧美做暖暖视频 | 日本人做爰大片免费观看一老师 | 久久综合爱 | 九九综合 | 黄一级| 四虎最新视频 | 国产专区免费 | 成人精品 | 久久久成人免费一区二区 | 一区二区三区视频在线观看 | 精品久久久久久久久久久久久久 | 国产精品欧美一区二区三区不卡 | 91xxx在线观看| 中文字幕91| 在线播放中文字幕 | 欧美三级在线 | 在线观看日韩av | 国产精品久久久久久模特 | 91国在线观看 | 久久久久国产一区二区三区四区 | 中文字幕视频在线观看 | 欧美精品福利 | 午夜影院在线观看 | 成人久久18免费网站 | 午夜影院在线观看免费 | 免费99视频 | 午夜国产一级 | 精品一区久久 | 久久成人精品视频 | japan25hdxxxx日本 做a的各种视频 |