Test — ATtiny85 simulation

An interactive ATtiny85 circuit simulation you can run free in your browser on Velxio, by cheelingoh612.

Components

Sketch code

// ATtiny85 — Button on PB0, LED on PB1
// Button wiring: one leg to PB0, other leg to GND
// INPUT_PULLUP means HIGH = released, LOW = pressed

const int MOTOR_IN1  = 1; // PB1 (Physical Pin 2)
const int MOTOR_IN2  = 4; // PB4 (Physical Pin 3)

const int SWITCH1   = 0;
const int SWITCH2   = 3;

void setup() {
  pinMode(MOTOR_IN1, OUTPUT);
  pinMode(MOTOR_IN2, OUTPUT);
}

void stopMotor() {
  digitalWrite(MOTOR_IN1, LOW);
  digitalWrite(MOTOR_IN2, LOW);
  analogWrite(2,0); 
}

void openGate() {
  // Only run motor if the 'Fully Open' limit switch is NOT pressed

  if (digitalRead(SWITCH1 == HIGH)){
    digitalWrite(MOTOR_IN1, HIGH);
    digitalWrite(MOTOR_IN2, LOW);
    analogWrite(2,200); 
  }
  else
  stopMotor();
}

void closeGate() {
  // Only run motor if the 'Fully Open' limit switch is NOT pressed

    if (digitalRead(SWITCH1 == HIGH)){
    digitalWrite(MOTOR_IN1, LOW);
    digitalWrite(MOTOR_IN2, HIGH);
    analogWrite(2,200);
  }
  else
  stopMotor();
}

void loop() {

if (digitalRead(SWITCH1 == HIGH)) {
    openGate();
}
else{
  stopMotor();
}

if (digitalRead(SWITCH2 == HIGH)){
    closeGate();
}
else{
  stopMotor();
}
}