Этот учебник является частью: Клавиатуры
Здесь перечислены все видеоролики с демонстрацией работы клавиатуры.
Controlling an 8-channel relay with a 4x3 keypad
This Arduino code is to control eight AC or eight DC loads connected to an eight-channel relay with a 4x3 keypad. Related Code and Videos 1-4 Keys Keypad2-4x3 Keypad
3-4x4 Keypad
4-4x4 Keypad Black (hard shell)
5-5x4 Keypad
6-4x3 Keypad: Controlling 8 Channel Relay
Resources for this code Library code for 4x4 Keypad Get a schematic diagram for this sketch from the Arduino Course on Udemy Learn Arduino step by step from beginner to advanced (Course) Get early access to my videos via Patreon
Этот учебник является частью: Клавиатуры
- Using 4x3 Keypad with Arduino
- Arduino Code and Video for a Four-Key Keypad
- Arduino Code and Video: 4x4 Matrix Black Keypad
- Build a Simple Electronic Lock with Keypad and LCD Using Arduino
- How to use 4x4 Soft Keypad with Arduino
- How to Use a 5x4 20-Key Keypad with Arduino to Detect Strings
- Lesson 67: Controlling an 8-Channel Relay with a Keypad Using Arduino
- 1602 LCD Keypad Shield: Basic Code
189-Resources for this code
Язык: C++
/*
* Library taken from: https://playground.arduino.cc/Code/Keypad
* This is the Arduino code for a 4x3 keypad with an 8-channel relay.
* Watch the video for details and a demo.
*
* Written by Ahmad Shamshiri for Robojax.com
* on February 4, 2019 at 18:01 in Ajax, Ontario, Canada.
* Permission granted to share this code, provided that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purposes only.
* This code has been downloaded from https://robojax.com
*
*/
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
// start of keypad settings
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// end of keypad settings
// start of relay settings
const int relayPin[]={9,10,11,12, 13, 14, 15, 16};// output pins where 8 relays will be connected
String relayNames[] ={"CH1", "CH2","CH3","CH4","CH5","CH6","CH7","CH8"};// Just put name for 8 relays
// do not change lines bellow
int pushed[] ={0,0,0,0, 0,0,0,0};// status of each buttons
int relayStatus[] ={HIGH,HIGH,HIGH,HIGH, HIGH,HIGH,HIGH,HIGH};// initial status of relay
// end of relay settings
void setup(){
// Robojax 4x3 keypad with 8ch Relay test
Serial.begin(9600);
for(int i=0; i<8; i++)
{
pinMode(relayPin[i], OUTPUT); // set relay pins as output
digitalWrite(relayPin[i], HIGH);// initial relay status to be OFF
}
Serial.println("Robojax 8 channel relay keypad");
}
void loop(){
// Robojax 4x3 keypad with 8ch Relay test
int val;
int knum;
char key = keypad.getKey();
// just print the pressed key
if(key && key !='*' && key !='#' && key !='0' && key !='9' ){
knum = (int)key-49;// convert char to integer (one less)
if(knum>=0 && knum<8){
//Serial.println(knum);
if(relayStatus[knum] == LOW){
pushed[knum] = 1-pushed[knum];
delay(50);
}// if
controlRelay(knum);// turn relay ON or OFF
}
}else{
val = LOW;
}
if(knum>=0 && knum<8){
relayStatus[knum] = val;
}
delay(50);
}// loop end
/*
*
* @brief Turns the relay ON or OFF
* @param relayPin is integer pin of relay
* @return no return value
* Written by Ahmad Shamshiri for Robojax.com
*/
void controlRelay(int number)
{
if(pushed[number] == 1)
{
digitalWrite(relayPin[number], LOW);// Turn ON relay
Serial.print(relayNames[number]);
Serial.println(" ON");
}else{
digitalWrite(relayPin[number], HIGH); // turn OFF
Serial.print(relayNames[number]);
Serial.println(" OFF");
}
// Robojax 4x3 keypad with 8ch Relay test
}//controlRelay end
Ресурсы и ссылки
Ресурсов пока нет.
Файлы📁
Нет доступных файлов.