Toggle pin high and low when pen moves up and down

Shop Forum Makelangelo Polargraph Art Robot Toggle pin high and low when pen moves up and down

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #13112
    Anonymous
    Inactive

    I’m trying to edit the firmware, so that when the servo position goes from down to up, a digital pin also goes from high to low, and vice versa. I think I finally found the command that actually changes the servo position from up to down. I believe it’s this right here, which is in the function “ISR(TIMER1_COMPA_vect)” in the motor.ino file.

    //move the z axis
    servos[0].write(working_seg->a[2].step_count);
    digitalWrite(12,!digitalRead(12));

    I added that third line line of code after that, and now my LED toggles on and off, but I need to add logic to it so the LED pin goes high when the pen is down and low when the pen is up. Can someone tell me what “working_seg->a[2].step_count” is? I assumed it would be a number between 0 and 180, but I wrote an if statement (something like “if (working_seg->a[2].step_count > 80)”), and it didn’t seem to work.

    Maybe I’m way off track here and there’s a better way to do this, but I’m at a loss now.

    I’m working with the Rumba firmware and a homemade robot based on an Arduino Mega.

    Thanks!

    #13113
    Dan
    Keymaster

    step_count is the position on a given axis, in motor steps. for the third axis (servo) it’s the angle. So if your up angle is 90 and your down angle is 50, you can check those two values and change the light at that time.

    The firmware does not currently care what angle you ask for. By that I mean it doesn’t know that 90 means up and 50 means down. You tell it to go and it sends the command to the servo and it’s job is done.

    #13129
    Anonymous
    Inactive

    Thanks Dan! It’s working now. I don’t know what was going wrong before, and I thought I had some kind of variable type mismatch.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.