First, I need to talk a little about myself. I started with Electronics with only 13 years old and until some months ago I was afraid about the uprocessors. Using digital components to do the things. I'm Electronics Technician and I'm doing college now in Telecommunications Enginniering.This project is to control a motor with two snap-action switchs.
I tried to do this with keeping two inputs at the same time to do a AND port. But I think that It isn't the right way, is it? Please, read my code and help me in what direction could I do to do this because there is this options:
Snap-On Right actioned, the rotor only can go to Left.
Snap-On Left actioned, the rotor only can go to Right.
Snap-On not actioned, the rotor can go to the two directions.
/*
Programa para controle de rotor de antenas
Este programa controla um rotor de antenas de radioamador
Sua função é verificar se as chaves de fim de curso estão
acionadas, se sim, o rotor pode ir para o lado contrário
senão, podem rodar para qualquer lado */
const int rotorL = 14 //escolhe o pino 14 como saida para o controle LEFT do rotor
const int rotorR = 15 //escolhe o pino 15 como saida para o controle RIGHT do rotor
const int switchSL = 16 //Chave de fim de curso LEFT no pino 16
const int switchSR = 17 //Chave de fim de curso RIGHT no pino 17
const int switchL = 18 //Chave LEFT
const int switchR = 19 //Chave RIGHT
void setup() {
pinmode(rotorL, OUTPUT);
pinmode(rotorR, OUTPUT);
pinmode(switchSL, INPUT);
pinmode(switchSR, INPUT);
pinmode(switchL, INPUT);
pinmode(switchR, INPUT);
}
void loop(){
int val = digitalRead(switchSL); // Lê o FDC Left
int val = digitalRead(switchSR); // Lê o FDC Right
if (val == HIGH) //checa se os dois valores estão em nivel 1
{
digitalWrite(rotorL, LOW);
digitalWrite(rotorR, LOW);
}
int val = digitalRead(switchL); // Lê a chave LEFT
if (val == HIGH) // Se o valor dela for 1
{
digitalWrite(rotorL, HIGH); // Liga o motor para o lado direito
}
int val = digitalRead(switchR); //Lê a chave RIGHT
if (val == HIGH)
{
digitalWrite(rotorR, HIGH);
}
int val = digitalRead(switchR)
int val = digitalRead(switchL)
if (val == HIGH)
{
digitalWrite(rotorL, LOW)
digitalWrite(rotorR, LOW)
}
}
My best regards, or 73s in the way that We talk in ham radio.
PY1CX - Felipe Navarro