Kód: Vybrať všetko
/*
Demonstrates the use of an array to hold pin numbers.
Each time the push button is pressed, next RELAY in the
sequence will be turned on while the rest of RELAY´s are off.
*/
const int buttonPin = 2; // the number of the pushbutton pin
const int relayPin1 = 3; // the number of the Relay1 pin
const int relayPin2 = 4; // the number of the Relay2 pin
const int relayPin3 = 5; // the number of the Relay3 pin
const int relayPin4 = 6; // the number of the Relay4 pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonPressCount = 0;
int numberOfRELAY = 4;
void setup() {
// initialize the Relay pin as an output:
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
pinMode(relayPin3, OUTPUT);
pinMode(relayPin4, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
//Turn OFF any power to the Relay channels
digitalWrite(relayPin1,LOW);
digitalWrite(relayPin2,HIGH);
digitalWrite(relayPin3,HIGH);
digitalWrite(relayPin4,HIGH);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
if (buttonPressCount % numberOfRELAY == 0) {
// turn Relay1 on:
digitalWrite(relayPin1, LOW);
} else {
digitalWrite(relayPin1, HIGH);
}
if (buttonPressCount % numberOfRELAY == 1) {
// turn Relay2 on:
digitalWrite(relayPin2, LOW);
} else {
digitalWrite(relayPin2, HIGH);
}
if (buttonPressCount % numberOfRELAY == 2) {
// turn Relay3 on:
digitalWrite(relayPin3, LOW);
} else {
digitalWrite(relayPin3, HIGH);
}
if (buttonPressCount % numberOfRELAY == 3) {
// turn Relay4 on:
digitalWrite(relayPin4, LOW);
} else {
digitalWrite(relayPin4, HIGH);
}
buttonPressCount++;
delay(400);
}
}
Chcel by som ale ešte pomocou 8x8 MAX7219 matrix displeja zobrazovať číslo práve zopnutého relé. Čiže zopnuté relé 1 na displeji svieti 1, zopnuté relé 2 na displeji svieti 2, atď. Viete mi stým niekto nejako pomôcť,s úpravou kódu, nejaké pomocné indície , funkčné odkazy-príklady, budem Vám veľmi vďačný za každú pomoc. Som samouk,začiatočník, snáď Vás to nebude obťažovať. Vopred veľmi pekne ďakujem za každú pomoc.