Hey guys I am trying to program pneumatics for my robot using EasyC V4 and I am having some trouble.
I am using a double acting piston and I want it to be programmed so that when I hit the Channel 5 Up button it goes in until I hit the button again.
Right now I have this:
When I download this code into the brain and I press the button the piston only retracts when the button is pressed. I want the piston to stay retracted until I hit the button again.
Please Help
You need to change the state of the digital output every time you see a 0 to 1 transition on the button, but only do it once until the button is released again. Hopefully that code is correct, I don’t really use EasyC.
Pretty much, however, “==” is comparison not assignment. So replace the lines like.
button_is_pressed == 1;
with
button_is_pressed = 1;
just need to use one “=”
I did not test the code so what’s important to understand is the principle behind it. You want to detect the button press and change the state of the output. You only want to do this once until the button is released. button_is_pressed is a variable that is used to store the fact that the button was pressed the last time around the while loop. You could also replace the weird output_state line I had used with…
ok this helps I will test this tomorrow at school.
Also do you know how to program the controller so that the arm raises to a certain position at the push of a button?
Thank you very much
ok I am trying to program it so that I can use 2 pistons and I copied the program you showed me but it isn’t working. It downloads without problem but when I got to press the buttons nothing happens.
Look closely at the code, it’s not quite what I posted. If the while statement is to be considered line 1, then line 6 is incorrect, should be “left_button_is_pressed”. Same with line 18 (but obviously right button).
Ok, I’m trying to help but you are not reading the example and typing it in correctly. Perhaps I should have not used names which were so similar, my fault. In an effort to get you over this hurdle, I have entered it for you, I can not test fully but it should work. This was created using EasyC 4.0.2.7 but would I assume work on earlier versions.
You should also check out JoysticktoDigitalLatch as jgraber mentioned. Not sure but it may also do the job. button_test.zip (2.11 KB)
Ok thanks! I got the code working and I programmed it so that with the press of 1 button 2 pistons work the same. Thank you for the help.
Right now I am working on the other program I told you about and I just don’t know where to start.
I want to make it so that when the Channel 6 Up button is pressed once the lift will raise to a certain position.
To be able to help with the lift would require more detailed information on your design and what sensors you have incorporated (or could add to the design).
It’s clear that you are just beginning to learn programming. Learning to program like everything else takes time and effort, however, one of the things that my colleagues constantly remind me of is that software can easily be changed. Therefore, try out the different functions that EasyC provides, play with the different sensors you have available to see what they do, start with simple code and gradually add more until you are comfortable with the toolset EasyC provides. There are lots of posts on this forum talking about how to achieve the same goal as you have, controlling motors to move something to a position without user intervention.
In a few days post back with a plan. Tell us what you have tried, what worked and what you don’t understand. When you have a plan I will be happy to continue to help. Good Luck.