1

Topic: Blinking LED

Hello all, I just started with Arduino so I could use a little help. I understand how to make an LED blink but not sure of the correct code to use a switch in RemoteXY to turn the LED on and off (blinking when on)? I want it to turn a beacon on and off on my mini loader tractor (two fast blinks, pause, one blink, pause...... repeat until switched off. Any help would be great! Thank you.

2 (edited by Daba 2018-05-27 14:43:25)

Re: Blinking LED

You will need to write a "toggle" function in your Arduino sketch, driven by the pushbutton on RemoteXY.

What I have found is that you need to write the button off as soon as you see it on, otherwise RemoteXY will keep it on as long as you keep the button pressed, and your toggle will keep going...

Here I've done exactly that for a "Save to EPROM" button in my sketch...

// respond to the Save button
  if (RemoteXY.save_button) {
    RemoteXY.save_button = 0;

    settingsSAVE();
}

With the code above, no matter how long you keep the button pressed, it is only seen once ...

2B, or not 2B, that is the pencil ...

3

Re: Blinking LED

Interesting thank you, I will play around with that and see if I can get it.

4

Re: Blinking LED

I have actually changed the button to a switch, here is my base code....


  // input variable
  int8_t slider_1; // =0..100 slider position
  int8_t joystick_2_x; // =-100..100 x-coordinate joystick position
  int8_t joystick_2_y; // =-100..100 y-coordinate joystick position
  uint8_t switch_1; // =1 if switch ON and =0 if OFF

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////

#define PIN_SWITCH_1 13


void setup()

{
  RemoteXY_Init ();
 
  pinMode (PIN_SWITCH_1, OUTPUT);
 
  // TODO you setup code
 
}

void loop()
{
  RemoteXY_Handler ();
 
  digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH);




 
  // TODO you loop code
  // use the RemoteXY structure for data transfer


}