キーパッドの「0」を押すと、ボードのLEDが光る
https://gyazo.com/ff83b3413b5bfafc94f0f005b7dada6d
更新
企画・製作
使ったもの
回路図
https://gyazo.com/d7564d448136567fa754874c94e26315
上記画像の、緑・白・5V・GNDの配線は不要
コード
code:.ino
const byte ROWS = 4; //4行のキーパッドを使用
const byte COLS = 4; //4列のキーパッドを使用
int flag=1;
{'3','7','b','f'},
{'2','6','a','e'},
{'1','5','9','d'},
{'0','4','8','c'}
};
byte rowPinsROWS = {5, 4, 3, 2}; //connect to the row pinouts of the keypad byte colPinsCOLS = {9, 8, 7, 6}; //connect to the column pinouts of the keypad Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(){
char customKey = customKeypad.getKey();//押されたキーを検出
if (customKey){
Serial.println(customKey);
Serial.println(flag);
if((customKey=='0') && (flag==1)){
digitalWrite(LED_BUILTIN, HIGH);
}
if((customKey=='0') && (flag==-1)){
digitalWrite(LED_BUILTIN, LOW);
}
flag=flag*-1;
}
}
↓ 動かない
code:.ino
const byte ROWS = 4; //4行のキーパッドを使用
const byte COLS = 4; //4列のキーパッドを使用
//-----------------------
// フラグの定義
//-----------------------
const int FLG_ON = 1;
const int FLG_OFF = 0;
{'3','7','b','f'},
{'2','6','a','e'},
{'1','5','9','d'},
{'0','4','8','c'}
};
byte rowPinsROWS = {5, 4, 3, 2}; //connect to the row pinouts of the keypad byte colPinsCOLS = {9, 8, 7, 6}; //connect to the column pinouts of the keypad Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(){
char customKey = customKeypad.getKey();//押されたキーを検出
if (customKey){
Serial.println(customKey);
if(t_f==1)
if(customKey=='0'){
digitalWrite(LED_BUILTIN, HIGH);
t_f=1;
tx_f=-1;
}else{
digitalWrite(LED_BUILTIN, LOW);
}
}
}