Input – output

ted
Fri Aug 24, 2018 2:04 pm
Hi
Input – output
I am trying to have the same pulses on pin PA7 as on PB12.
No pulses on PA7, what I doing wrong ?

int state = LOW;
int lastState = LOW;

void setup()
{
pinMode(PB12, INPUT);
pinMode(PB7, OUTPUT);
state = digitalRead(PB12);
}

void loop()
{
if (state == HIGH )
//if (state == HIGH && lastState == LOW)
digitalWrite (PB7, HIGH);
else
digitalWrite (PB7, LOW);
//delay(300);
}


zmemw16
Fri Aug 24, 2018 2:08 pm
your text says PA7, your code says PB7 ?

// lastState – it gets set, but what changes this ? missing > lastState = State; < me duh


ted
Fri Aug 24, 2018 2:13 pm
Correction to text – PB7

ted
Fri Aug 24, 2018 2:27 pm
I’ve done so, still nothing on PB7

int state = LOW;
int lastState = LOW;
int State;

void setup()
{
pinMode(PB12, INPUT);
pinMode(PB7, OUTPUT);
state = digitalRead(PB12);
lastState = State;
}

void loop()
{
if (state == HIGH )
//if (state == HIGH && lastState == LOW)
digitalWrite (PB7, HIGH);
else
digitalWrite (PB7, LOW);
//delay(300);
}


edogaldo
Fri Aug 24, 2018 2:31 pm
What about reading the state in the loop?!

ted
Fri Aug 24, 2018 2:36 pm
if (state == HIGH )

edogaldo
Fri Aug 24, 2018 2:39 pm
void setup()
{
pinMode(PB12, INPUT);
pinMode(PB7, OUTPUT);
}

void loop()
{
digitalWrite(PB7, digitalRead(PB12));
}


ted
Fri Aug 24, 2018 2:50 pm
Excellent, thank you.
Now I will try with delay to achieve Phase Shift

ted
Fri Aug 24, 2018 3:14 pm
Unfortunately delay is not working with you solution.
void setup()
{
pinMode(PB12, INPUT);
pinMode(PB7, OUTPUT);
}

void loop()
{
// digitalWrite(PB7, digitalRead(PB12));
digitalWrite(PB7);
delay (30 );
digitalRead(PB12));

//delayMicroseconds(50);
//delay (30 ),
}


edogaldo
Fri Aug 24, 2018 3:59 pm
ted, you should at least try to make a compiling code..
what does it mean “digitalWrite(PB7);”? what are you writing in PB7?!
and do you know that programming languages generally require parenthesis balancing? “digitalRead(PB12));”: you have one open parenthesis and 2 close ones..
finally, implementing a signal phase shifting is not trivial: it requires you store the read value in a buffer and read it after the delay is occurred but you should not use the delay() function, else you won’t be able to keep on reading the input while waiting for delay() finishes..

ted
Fri Aug 24, 2018 6:13 pm
Thanks for explanations, I thought I found easy way to make a phase shifter

Leave a Reply

Your email address will not be published. Required fields are marked *