A motor with snap-action in two directions.

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

Try this - need to use 2 inputs

and then don't use same variable to read both of them:

int val = digitalRead(switchR)
int val = digitalRead(switchL)
if (val == HIGH)

Some problems solved..

/*
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),(switchSR); // Lê o FDC Left e Right
if (val == HIGH) //checa se os dois valores estão em nivel 1
{
digitalWrite(rotorL, LOW),(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),(switchL);
if (val == HIGH)
{
digitalWrite(rotorL, LOW),(rotorR, LOW);
}
}

In the compilation I see:

COMANDO_DE_ROTOR_ARDUINO.cpp: In function 'void loop()':
COMANDO_DE_ROTOR_ARDUINO:51: error: expected }' at end of input COMANDO_DE_ROTOR_ARDUINO:51: error: expected }' at end of input

Use CTRL-T
It will reveal a mis-match in your ( )s and { }s .
In this case you need a } at the very end to finish up void loop()

You can also do this without using software:

http://web.comporium.net/~shb/switch.htm

...from a discussion on this thread:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1290399372

Courtesy of zoomkat...

:slight_smile: