Hello, I pieced this code together for an Attiny85 but I can't get it to work... I know I'm uploading correctly because the "blink" sketch works when I set the output pin to 0 as in PWM0 on attiny85... Any ideas? I'm trying to make a reed switch on PWM pin 1(6) turn PWM pin 0(5) to high when the reed is released and stay high. Also what I cannot figure out that would be awesome if someone knew how to do this easily is to make PWM 0 stay high for 5 seconds after the reed switch is released and then shut back down... Anyways, thanks for the help in advance!
const int buttonPin = 1; // the number of the pushbutton pin
const int steadyvoltagepin = 0; // the number of the steady volatage pin
int buttonState = 0;
void setup() {
// initialize the Steady voltage pin as an output:
pinMode(steadyvoltagepin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
//Give +5V continuously to the pin.
digitalWrite(steadyvoltagepin, HIGH);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// Generate pulse of 50% DC:
//for 50% dc of frequency 500Hz
digitalWrite(steadyvoltagepin, LOW);
} else {
// Donot Generate the pulse or give 0V:
digitalWrite(steadyvoltagepin, HIGH);//0V
}
}