Jump to content

Hi, I need help figuring out why Switch 3 is being printed no matter what. It does this properly for switch 1 and 2, but continues to print switch 3 as on, when it is off. Here is the picture of my code, sorry it’s not really legible...

 

EDIT: These are generic brand light switches from Walmart for $0.67 a piece, couldn’t resist. They work well too.

 

B84FDF4F-59EF-426A-AEEE-3D9927083C5D.jpeg

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/
Share on other sites

Link to post
Share on other sites

use different variable name fo input_value like input_value1 , input_value2,input_value3

and after the first if statement use elif

like this

input_value1
if input_value1 == false :
whatever
input_value2
elif input_value2 == false :
whatever

input_value3
elif input_value3 == false :
whatever

 

if it was useful give it a like :) btw if your into linux pay a visit here

 

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297183
Share on other sites

Link to post
Share on other sites

1 minute ago, mahyar said:

use different variable name fo input_value like input_value1 , input_value2,input_value3

and after the first if statement use elif

like this

 

*snip*

Let me try that

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297188
Share on other sites

Link to post
Share on other sites

Wait... now I am using the RPi.GPIO library, if I use those other variables, it’s now undefined so now what

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297193
Share on other sites

Link to post
Share on other sites

1 minute ago, TheCoder2019 said:

Wait... now I am using the RPi.GPIO library, if I use those other variables, it’s now undefined so now what

just use the output of library directly

dont add that input value thingy

if it was useful give it a like :) btw if your into linux pay a visit here

 

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297200
Share on other sites

Link to post
Share on other sites

How do I do that? I’m still kind of learning Python

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297202
Share on other sites

Link to post
Share on other sites

Like this?

 

GPIO.input(switchX, HIGH)

 

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297209
Share on other sites

Link to post
Share on other sites

Just now, mahyar said:

no 

if gpio.input(switchx) == false :

I’m gonna try it... I’ll try to be back in 5 mins?

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297213
Share on other sites

Link to post
Share on other sites

Just now, mahyar said:

btw use elif as i showed above

OK

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297219
Share on other sites

Link to post
Share on other sites

So I did elif statements and the terminal is still getting spammed by saying switch 3 is on

 

Is this code correct?

04B0AAD9-CE35-4F7C-ABD7-50E6F4012FDF.jpeg

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297224
Share on other sites

Link to post
Share on other sites

1 minute ago, TheCoder2019 said:

So I did elif statements and the terminal is still getting spammed by saying switch 3 is on

 

Is this code correct?

04B0AAD9-CE35-4F7C-ABD7-50E6F4012FDF.jpeg

well idk much more 

i usually code this sort of stuff c/c++ those were only things i could see wrong with your code

if it was useful give it a like :) btw if your into linux pay a visit here

 

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297229
Share on other sites

Link to post
Share on other sites

I DID notice when I switched Switch 3 to True, it would stop, but the light switch is now inverted which will annoy me. Anything there?

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297233
Share on other sites

Link to post
Share on other sites

5 minutes ago, TheCoder2019 said:

I DID notice when I switched Switch 3 to True, it would stop, but the light switch is now inverted which will annoy me. Anything there?

wait are you sure that led you are using is good? did you use pullup resistors? how are switches wired?

if it was useful give it a like :) btw if your into linux pay a visit here

 

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297239
Share on other sites

Link to post
Share on other sites

Let me draw it. This may take a while

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297241
Share on other sites

Link to post
Share on other sites

@mahyar K. Here it is. I am not using pullup resistors because they worked fine without, with no bouncing

 

 

burner.png

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297266
Share on other sites

Link to post
Share on other sites

2 minutes ago, TheCoder2019 said:

@mahyar K. Here it is. I am not using pullup resistors because they worked fine without, with no bouncing

 

 

burner.png

rpi has internal pullup resistors enablee them

if it was useful give it a like :) btw if your into linux pay a visit here

 

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297269
Share on other sites

Link to post
Share on other sites

How? sudo raspi-config? Or another bash command?

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297270
Share on other sites

Link to post
Share on other sites

Most of what I find is in Java. Do you mind sourcing the code for me? Sorry for being a pain, I’ll follow for your troubles with me

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297284
Share on other sites

Link to post
Share on other sites

That’s literally what I’ve just read 5 mins ago. It works well, no repeated echo. I would call this thread a success. Thank you for sticking around the 1 hour and 30 some minutes you did

specs

Spoiler

ASRock B650I Lightning WiFi

AMD Ryzen 7 7700X

KLEVV CRAS V RGB (2x16GB) 6000MT/s out of the 7200MT/s I could be running

ASUS RTX 3060 OC (12GB)

Thermalright Frozen Edge 240 RGB

Lian Li A4-H2O

 

linux packages

Spoiler

tmux

btop

git

Link to comment
https://linustechtips.com/topic/1280488-python-help/#findComment-14297301
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×