Friday, 1 June 2018

A silly problem that has been nagging for a time

Many products have buttons that create two function, press it for a short time - function one, press it for a longer time - function two. I have a use of this in a new project, to build a VFO for an SSB exciter.

Function one is to push the button on the tuning rotary encoder and change the tuning "step" from 10Hz per click to 1MHz per click.

Function two - the long press - is to switch from LSB to USB.

The code turned out to be simple:

Code

long hold;

  if (digitalRead(SW) == LOW) {         // sw push
    hold = millis();                    // start hold count
    while (!digitalRead(SW));           // wait release
    if (millis() - hold > HOLD) {       // sw push hold
      usb = !usb;
      // update USB/LSB freq
    }
    else
      // update step
 

No comments: