ATtiny85: Digital input (output) changing

Hi,

is it possible to realize a function like the picture shown?
I try it with the following sketch and the result is that UP and(!) DOWN are lightning.

Many thanks for ideas!
RABIS

/*
  UP and DOWN at 16 Mhz
 */

#include <avr/power.h> 
#include <Adafruit_NeoPixel.h>

#define N_PIXELS 6        // Number of pixels you are using
#define LED_PIN  1        // NeoPixel LED strand is connected to GPIO #1
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);

#define LEDS  3

const int Pin2  = 2;
const int Pin0  = 0;

bool   val_1    = 0;
bool   val_2    = 0;

// the setup routine runs once when you press reset:
void setup() {  
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);  
  //  pinMode(Pin2,INPUT);
  strip.begin();
}  

void stripeON() {
  uint8_t i,k;
  for (i=0; i<N_PIXELS; i++) {
    strip.setPixelColor(i,64,0,0);
  } 
  strip.show(); 
}  

void stripClear() {
  uint8_t i;
  for (i=0;i<N_PIXELS;i++) {
    strip.setPixelColor(i,0,0,0); 
  }
  strip.show();  
}  

void loop(){
  uint8_t i;
  stripeON();
  delay(1000);

  while (true) {
    stripClear();
    delay(500);
    pinMode(Pin0,OUTPUT);
    digitalWrite(Pin0,HIGH);
    pinMode(Pin0,INPUT);
    delay(10);
    pinMode(Pin2,OUTPUT);
    digitalWrite(Pin2,LOW);
    val_1 = digitalRead(Pin0);
    digitalWrite(Pin2,HIGH);
    
    if (!val_1) {
      for (i=N_PIXELS-LEDS;i<N_PIXELS;i++) {
        strip.setPixelColor(i,32,32,0); 
      }
      strip.show();
      delay(500);
    }
    pinMode(Pin2,OUTPUT);
    digitalWrite(Pin2,HIGH);
    pinMode(Pin2,INPUT);
    delay(10);
    pinMode(Pin0,OUTPUT);
    digitalWrite(Pin0,LOW);
    val_1 = digitalRead(Pin2);
    digitalWrite(Pin0,HIGH);

    if (!val_1) {
      for (i=0;i<LEDS;i++) {
        strip.setPixelColor(i,32,32,0); 
      }
      strip.show();
      delay(500);
    }
  }
}

ATtiny85_001.png

I don't get why you connect a switch like that? If it's not pushed PB0 and PB2 are connected because of the upper contact. But if you press the switch PB0 and PB2 are connected because of the lower contact. So they are always connected....

Hello,

thanks for answer. My idea was that two wires are enough for this function. The function of PBx is changed in program (digital output in digital input and reverse). How can I lock DOWN if UP is pressed?
The switch is open between UP and DOWN.

But you have just one switch :roll_eyes: