simpletools code to C conversion, can't figure it out.
Beavis3215
Posts: 229
I have some code examples for using DIRA, OUTA and waitpeq, but nothing as simple as the C equivalent of on_sensor = input(19) or if (on_sensor == 1).
Here is what I mean
This Works
This is what Im trying to do
Just tying to understand the inputs for now. It seems like I should be pretty close.
Is there somewhere in help that talks about this?
Here is what I mean
void button_time(); static volatile int delay; // delay is global int main() // Main function { cog_run(button_time,128); // Push button control runs in other cog set_directions(17,16,11); int on_sensor; int off_sensor; while(1) { on_sensor = input(19); off_sensor = input(18); if (on_sensor == 1) { set_output(17,1); // Turn magnet on } if (off_sensor == 1) { pause(delay); // Delay is assigned in button_time set_output(17,0); // Turn magnet off set_output(16,1); // Timing light on pause(5); set_output(16,0); // Timing light off } } }
This Works
This is what Im trying to do
void button_time(); static volatile int delay; // delay is global int main() // Main function { cog_run(button_time,128); // Push button control runs in other cog set_directions(17,16,11); int on_sensor = 1 << 19; int off_sensor = 1 << 18; DIRA &= ~(1 << 19); DIRA &= ~(1 << 18); while(1) { on_sensor = input(19); off_sensor= input(18); if (on_sensor == on_sensor) { set_output(17,1); // Turn magnet on } if (off_sensor == off_sensor) { pause(delay); // Delay is assigned in button_time set_output(17,0); // Turn magnet off set_output(16,1); // Timing light on pause(5); set_output(16,0); // Timing light off } } }
Just tying to understand the inputs for now. It seems like I should be pretty close.
Is there somewhere in help that talks about this?
Comments
(edited to correct syntax)
This doesn't change the direction of the IO pin which can be useful when using it to monitor the output state controlled by other processes.
Awesome as always
The simpletools code is remarked out as to be non operational. I am attempting to replace the simpletools code with C code, but I am making a mistake. I don't quite get it, any Ideas?
Dave, I also tried to find in simple libraries the C code conversions of simple code, but I can't find it. Can you get me the path through Simple IDE help to get to them?
But any other cog can make the pin an output, right?
To set the direction of the 6 bits to outputs you should do You can find the location of the library code by clicking on Tools and then Properties. Or you can just hit the F6 key. Look for "Library Folder" to find the location. The source for the pin I/O routines is located in the Utility/libsimpletools/source folder.
@Rayman, you are correct. Any other cog can make the pin an output.