ARC Pro

Upgrade to ARC Pro

Unleash your creativity with the power of easy robot programming using Synthiam ARC Pro

#1  

By switch, you mean an on off switch, right?

What you can do is pass a wire from the on side of the switch to a digital signal port (making sure that the voltage is regulated down to 5 volts). From there, the V4 will be able to see if that digital port is in a high or low state.


if(GetDigital(d0) = 1)
#do something if the switch is on
else
#do something if the switch is off
endif

BTW, example is available in the If condition in ARC script help


If (Value Condition Value )
IF condition can support multiple comparisons and functions.
Condition tree must be closed with an ENDIF
See the Functions section of this document.
Condition can be =, <, >, <=, >=, !=, AND, OR
Example: 
If (GetDigital(D0) = 1)
  Print(One)
EndIf
Example: 
If ($Day = 2 AND $Hour = 3)
  Print(Hello)
EndIf
Example: 
If (GetServo(D5) >20 OR ($x >= 3 and $y < 2))
  Print(Yup!)
EndIf



#2  

Thanks so much easer then Arduino's. So I'm going to put the switch a crossed the signal pin and ? (+ or - )? Thanks :)

#4  

Nothing other then being monitored by the EZ-B4 as in the state of OFF or ON. The switch is closed or NC when my robot is plugged into the shop sensor cable. Two wires represent the switch. The two wires at the end of a cable that has the shop PIR sensors on it. The two wires are solder to each other to for the switch in the closed position. So when the cables plugged in to the robot, its the same as a switch being turned on or in closed. So when the EZB4 sees the switch on it will set a variable named $LOCATION and it will = SHOP. If the cable is not plugged in it will = 0 . Thus telling my robot it is in the shop.

#5  

I assumed that you are talking about a switch as in an on/off switch that is supplying power to something. If this is the case, you would just come off of the on position of the pin to the v4 on a digital signal port. This port is a 5 volt port so it is necessary to then reduce the power down to 5 volts if it is being supplied more than 5 volts. This pin can then be monitored with a script for a high state. If it is high, it would return a 1 in the script (or on). If it is off or 0 volts, it would be 0 volts or off. The ground pin would probably have to be connected to the switch also but everything depends on what you are doing with the switch and how you are using it in your system.

It would work the same on an arduino. It is all based on low(0 volts) or high logic (5 volts). If it is some other type of switch, it would still depend on low or high logic, but how you supply that to the board from the switch could be different.

#6  

You replied while I was typing, let me go back and read that.

#7  

Here is how you would do it on an arduino. The same way can be used on a V4 only you would use the same pins in the digital port instead of pins from various parts of the board. The script above would work.

Connect three wires to the Arduino board. The first two, red and black, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10 KOhms) to ground. The other leg of the button connects to the 5 volt supply.

Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and reads as LOW, or 0. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, so that the pin reads as HIGH, or 1.

Switches come in many forms. Some have 2 pins on the back of the switch that would be used for something like power. Some have 3 pins and some have 4 pins. What configuration is your switch? Does it except ground and positive or just have 2 pins (in and out)?

#8  

I'm use to working with with the Arduino's. But that set-aside. For simplicity sake Lets say I have a switch. It is a DPST (Double pole single throw) When you turn it on the switch close the contacts. When you turn the switch off it opens the contacts. I need the EZB4 to set a variable when the switch is closed.

To do this one leg of the switch is connected to the S or signal pin on D0 and the other wire goes to the?

Dose the EZB4 have a built in pull down / pull up resistor ?

#9  

no, the v4 doesn't have built in pull up or down resistors on the digital pins. you would have to supply one.

How would you accomplish this on an arduino? It would be the same for the V4. The arduino would have to measure the pin (d2 for example) for high or low. in order to do that, you would have to have a breadboard or some circuit that provides the 5V or 0V back to the arduino on the d2 pin. You would have to provide the pullup or pull down resistor in the circuit. You would have to provide positive and neg to the circuit or breadboard because there is no voltage coming across the solution you mentioned.

With a double pole single throw switch, you could take the digital signal pin from say D0, pass it through the switch and read the result on D1. Set D0 to high and then measure on D1. If the switch has been switched, D1 would be high. if it isnt, D1 would be low. This would be the easiest way to do what you are looking for.


set(D0,on)
if(GetDigital(d1) = 1)
#the switch is in the on position
else
#the switch is in the off position
endif

This would work because there is a common ground between D0 and D1 (along with every other ground pin) on the V4.

#10  

Now I'm getting some where. Ok now I see how we are going to do this. Cool Thanks. :)

On The Arduino I use:



// Note one leg of the switch goes to the S or signal pin on pin set #2 and the other leg goes to the - (negative) pin on pin set # 2

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  
  pinMode(13, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(2, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(2);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:

  if (buttonState == HIGH) 
    {     
      // turn LED on:    
      digitalWrite(13, HIGH);  
    } 
  else {
     // turn LED off:
     digitalWrite(13, LOW); 
   }
}



#11  

Anytime bud. You're basically doing the same thing with 2 digital pins.

Glad to have been of help.

#12  

The EZB4 cant read from the Signal pin to ground? I thought it had built in pull ups and pull downs.... ?

#13  

You will just have to use the signal pin. D0 to one side of the switch. D1 to the other side of the switch. The V4 has power to the other pins that is common (ground and +). You wont have to worry about these at all and no wires are needed at all on these pins (+ or -).

If you set D0 to on then d1 should read high or the other way around depending on which you want to do. I dont have one available to test with right now, but I will do a test tonight for you.

#14  

Your last code works well. Just put your switch from S signal to - or ground and the port will go 1 or 0 depending on how the switch is set.