Search Header Logo
บทเรียนที่ไม่มีชื่อ

บทเรียนที่ไม่มีชื่อ

Assessment

Presentation

Instructional Technology

5th Grade

Hard

Created by

Godlike Tutor

Used 1+ times

FREE Resource

3 Slides • 0 Questions

1

By Godlike Tutor

​#include <Keypad.h>

const byte ROWS = 4;

const byte COLS = 4;

char keys[ROWS][COLS]=

{

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','#','D'}

};

byte rowPins[ROWS] = {9,8,7,6};

byte colPins[COLS] = {5,4,3,2};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup()

{

Serial.begin(9600);

}

void loop()

{

char key = keypad.getKey();

if (key != NO_KEY)

{

Serial.println(key);

}

}

2

​#include <Keypad.h>

const byte ROWS = 4;

const byte COLS = 4;

char keys[ROWS][COLS] =

{

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','#','D'}

};

byte rowPins[ROWS] = {9,8,7,6};

byte colPins[COLS] = {5,4,3,2};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// รหัสผ่านที่ต้องการ

const char correctPassword[] = "1234";

char enteredPassword[5]; // เก็บรหัสที่ผู้ใช้กรอก

byte passwordIndex = 0;

void setup()

{

Serial.begin(9600);

}

void loop()

{

char key = keypad.getKey();

if (key != NO_KEY) {

// ถ้ากดปุ่ม *

if (key == '*') {

// รีเซ็ตรหัสผ่านที่กรอกแล้ว

passwordIndex = 0;

memset(enteredPassword, 0, sizeof(enteredPassword));

Serial.println("Password reset.");

}

// ถ้ากดปุ่ม #

else if (key == '#') {

// ตรวจสอบรหัสผ่านที่กรอก

enteredPassword[passwordIndex] = '\0'; // ใส่ null-terminator สำหรับการตรวจสอบ

if (strcmp(enteredPassword, correctPassword) == 0) {

Serial.println("Password Correct!");

} else {

Serial.println("Incorrect Password.");

}

// รีเซ็ตรหัสผ่านที่กรอกแล้ว

passwordIndex = 0;

memset(enteredPassword, 0, sizeof(enteredPassword));

}

// ถ้ากดปุ่มตัวเลข

else {

if (passwordIndex < 4) {

enteredPassword[passwordIndex] = key; // เก็บคีย์ที่กรอก

passwordIndex++;

Serial.print("Entered: ");

Serial.println(enteredPassword);

}

}

}

}




By Godlike Tutor

​#include <Keypad.h>

const byte ROWS = 4;

const byte COLS = 4;

char keys[ROWS][COLS]=

{

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','#','D'}

};

byte rowPins[ROWS] = {9,8,7,6};

byte colPins[COLS] = {5,4,3,2};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup()

{

Serial.begin(9600);

}

void loop()

{

char key = keypad.getKey();

if (key != NO_KEY)

{

Serial.println(key);

}

}

Show answer

Auto Play

Slide 1 / 3

SLIDE

Discover more resources for Instructional Technology