zoukankan      html  css  js  c++  java
  • Arduino 4X3键盘 AD模拟分量实现

    //读分量测试
    
    ----------------
    
    int keyboardPin = 0;    //模拟口0
    
     int keyboardValue = 0;   // 取得键AD模拟分量
    
    
    
    
    
     void setup() {
    
       //通信波特率
    
       Serial.begin(9600); 
    
    
    
     }
    
    
    
     void loop() {
    
       keyboardValue = analogRead(keyboardPin); // read the pot value
    
      
    
       Serial.println(keyboardValue);      // 串口打印
    
       delay(1000);                  
    
     }
    
    ---------------------------------------------------------
    
    int keypressed = 0;
    
    int keyboardPin = 0;    
    
    int keyboardValue = 0;  
    
    
    
    void setup(){
    
      Serial.begin(9600); 
    
    }
    
    
    
    
    
    void loop(){
    
     
    
     keyboardValue = analogRead(keyboardPin); //AD分量范围2的10次方
    
     while (keyboardValue < 25){
    
       //监听模拟口
    
     keyboardValue = analogRead(keyboardPin); 
    
     delay(50);             
    
     readkeyboard(); 
    
     
    
    }
    
    
    
    void readkeyboard(){
    
       keyboardValue = analogRead(keyboardPin);
    
       if (keyboardValue <25){keypressed = 0;}
    
       if ((keyboardValue >25) && (keyboardValue < 67)){keypressed = 1;}
    
       if ((keyboardValue >67) && (keyboardValue < 108)){keypressed = 2;}
    
       if ((keyboardValue >108) && (keyboardValue < 162)){keypressed = 3;}
    
       if ((keyboardValue >162) && (keyboardValue < 253)){keypressed = 4;}
    
       if ((keyboardValue >253) && (keyboardValue < 361)){keypressed = 5;}
    
       if ((keyboardValue >361) && (keyboardValue < 479)){keypressed = 6;}
    
       if ((keyboardValue >479) && (keyboardValue < 619)){keypressed = 7;}
    
       if ((keyboardValue >619) && (keyboardValue < 765)){keypressed = 8;}
    
       if ((keyboardValue >765) && (keyboardValue < 819)){keypressed = 9;}
    
       if ((keyboardValue >819) && (keyboardValue < 889)){keypressed = 0;}
    
       if ((keyboardValue >889) && (keyboardValue < 938)){keypressed = 0;}
    
       if (keyboardValue >938){keypressed = 0;}
    
    
    
       while (keyboardValue > 25) {
    
         delay (100);
    
         keyboardValue = analogRead(keyboardPin);
    
       }
    
    
    
       Serial.println(keypressed);     
    
       delay(1000);                    
    
                         }
    View Code
  • 相关阅读:
    《机器学习》第二次作业——第四章学习记录和心得
    机器学习一到三章笔记
    [ML] 第四章学习总结
    [CV] Mnist手写数字分类
    ModelArts (华为GPU/CPU计算云平台)体验
    [DataSturcture] 红黑树求逆序对
    [CV] 边缘提取和角点判断
    [CV] 灰度共生矩阵
    [DataStructure] AC 自动机(Aho–Corasick Automata)
    [GIT] 如何删除git上保存的文件(包含历史文件)
  • 原文地址:https://www.cnblogs.com/darkdance/p/4923230.html
Copyright © 2011-2022 走看看