Stryfeduino – Part 2 – It’s alive

By | 8. July 2016

LED and Buttons


The new location for the toggle switch and the three new items will be above the battery holder. Before we mark the positions for the holes, first check the dimensions of the Ethernet module and use only the remaining space to avoid problems. After we marked four equidistant locations drill we work our way up from a small to a large drill to finish with a nice hole.

I chose the arrangement of: Action button, Reset button, Power toggle, Status LED from fromt to back.

Stryfeduino - RC - 34 - Enc28 fitting Stryfeduino - RC - 41 - Input holes 1 Stryfeduino - RC - 43 - Input holes 4 Stryfeduino - RC - 44 - Input holes 7 Stryfeduino - RC - 45 - Input holes 8

Wiring

Reset Button

That’s really easy, we only need to connect the button to the reset and GND pin of the Arduino.

Action Button

Also easy, we connect the 3.3V from the Arduino to one side of the button. The other side of the button is connected to the D4 pin of the Arduino and also with a 10 kOhm resistor to a GND pin.

Stryfeduino - RC - 48 - Circuit Button

Status LED

We connect the long pin to the D4 pin of the Arduino with an appropriate resistor and the short pin to GND.

Stryfeduino - RC - 49 - Circuit LED

Implementation

Action Button

This is a modified version of the Debounce Example from the Arduino IDE which will call a function when the button is pressed instead of bringing a LED to light.

const int buttonPin = 4;
int buttonState;
int lastButtonState = LOW;
long lastDebounceTime = 0;
long debounceDelay = 50;
 
void setup() {
  pinMode(buttonPin, INPUT);
}
 
void doButton(
  // things to do when the button is pushed
}
 
void loop() {
  int reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {
    lastDebounceTime = millis();
  }
 
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading != buttonState) {
      buttonState = reading;
 
      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH) {
        doButton();
      }
    }
  }
 
  lastButtonState = reading;
}

Status LED

Pretty much the same as the transistor code.

const int ledPin = 4;
 
void setup() {
  pinMode(ledPin, OUTPUT);
}
 
void loop() {
  delay(1000);
  // Turn the led on
  digitalWrite(ledPin, HIGH);
  
  delay(1000);
  // Turn the led off
  digitalWrite(ledPin, LOW);
}

Leave a Reply