เพิ่มการเช็ค

เพิ่มการเช็ค

diff --git a/Arduino/arduino_push_keypad_2_digits/.vscode/arduino.json b/Arduino/arduino_push_keypad_2_digits/.vscode/arduino.json
index c3d82de..5d9969f 100644
--- a/Arduino/arduino_push_keypad_2_digits/.vscode/arduino.json
+++ b/Arduino/arduino_push_keypad_2_digits/.vscode/arduino.json
@@ -1,5 +1,5 @@
 {
     "board": "arduino:avr:uno",
     "sketch": "arduino_push_keypad_2_digits.ino",
-    "port": "COM16"
+    "port": "COM4"
 }
\ No newline at end of file
diff --git a/Arduino/arduino_push_keypad_2_digits/arduino_push_keypad_2_digits.ino b/Arduino/arduino_push_keypad_2_digits/arduino_push_keypad_2_digits.ino
index 1beb85a..bbef19a 100644
--- a/Arduino/arduino_push_keypad_2_digits/arduino_push_keypad_2_digits.ino
+++ b/Arduino/arduino_push_keypad_2_digits/arduino_push_keypad_2_digits.ino
@@ -8,58 +8,81 @@ const byte COLS = 3; //three columns
 int inputA1;
 
 char keys[ROWS][COLS] = {
-  {'1','2','3'},
-  {'4','5','6'},
-  {'7','8','9'},
-  {'*','0','#'}
-};
+    {'1', '2', '3'},
+    {'4', '5', '6'},
+    {'7', '8', '9'},
+    {'*', '0', '#'}};
 byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
-byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad
+byte colPins[COLS] = {4, 3, 2};    //connect to the column pinouts of the keypad
 
 //Create an object of keypad
-Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
-
-void setup(){
-  pinMode(9, OUTPUT);
-TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(COM1B0) | _BV(WGM11); 
-TCCR1B = _BV(WGM13) | _BV(CS11);
-  
-  Serial.begin(9600);
+Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
+
+void setup()
+{
+    pinMode(9, OUTPUT);
+    TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(COM1B0) | _BV(WGM11);
+    TCCR1B = _BV(WGM13) | _BV(CS11);
+
+    Serial.begin(9600);
 }
 
 char key;
 int ckey = 0;
-void loop(){  
- 
-
-  key = keypad.getKey();// Read the key
-
-if (key != NO_KEY)
+String varKey1 = "";
+String varKey2 = "";
+void loop()
 {
-Serial.println(key);
-}
-
-if(ckey == 2){
-  if(key == '0'){ //เมื่อ กด 0 เข้าเงื่อนไขนี้
-      inputA1 = 1024; // แทนค่า inputA1 ด้วย 1024 ที่ทำให้ PWM มี dutycycle 5 %
-      Serial.println(String("Read inputA1 = ")+ inputA1);
-  }
-  if(key == '1'){ //เมื่อ กด 1 เข้าเงื่อนไขนี้
-      inputA1 = 900; // แทนค่า inputA1 ด้วย 900 ที่ทำให้ PWM มี dutycycle 10 %
-      Serial.println(String("Read inputA1 = ")+ inputA1);
-  }
-
-
- ICR1 = 62.5; 
-pwm1 = inputA1; 
-
-xxx = float(pwm1);
-
-xxx = xxx * ICR1;
-
-xxx = xxx / 512;
-
-OCR1A = int(62.5-(xxx/2));
 
-  }
+    while (ckey == 0)
+    {
+        key = keypad.getKey(); // Read the key
+
+        if (key != NO_KEY)
+        {
+            Serial.println(key);
+            varKey1 = String(key);
+            ckey++;
+        }
+    }
+
+    while (ckey == 1)
+    {
+        key = keypad.getKey(); // Read the key
+
+        if (key != NO_KEY)
+        {
+            Serial.println(key);
+            varKey2 = String(key);
+            ckey++;
+        }
+    }
+
+    if (ckey == 2)
+    {
+        String KeySum = varKey1 + varKey2;
+        Serial.println(String("KeySum = ") + KeySum);
+        if (KeySum == "15")
+        {                  //เมื่อ กด 0 เข้าเงื่อนไขนี้
+            inputA1 = 950; // แทนค่า inputA1 ด้วย 1024 ที่ทำให้ PWM มี dutycycle 5 %
+            Serial.println(String("Read inputA1 = ") + inputA1);
+        }
+        if (KeySum == "20")
+        {                  //เมื่อ กด 1 เข้าเงื่อนไขนี้
+            inputA1 = 900; // แทนค่า inputA1 ด้วย 900 ที่ทำให้ PWM มี dutycycle 10 %
+            Serial.println(String("Read inputA1 = ") + inputA1);
+        }
+
+        ICR1 = 62.5;
+        pwm1 = inputA1;
+
+        xxx = float(pwm1);
+
+        xxx = xxx * ICR1;
+
+        xxx = xxx / 512;
+
+        OCR1A = int(62.5 - (xxx / 2));
+        ckey = 0;
+    }
 }
\ No newline at end of file

GitHub
sha: 35983e73