Confusion with ULN2803 and IR sensor power

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#21 Post by jph »

Second ones way cleaner
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#22 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 7:53 pm

Code: Select all

function input_change1(state)
    log(state)
    state = not state  
    log(state)
end
I knew there must be a cleaner way - a bit more boolean, it works this time though :D :roll:
So where do I place this snippet of your code in the code that Keith gave me today?
image.png

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#23 Post by jph »

Kaellis991 wrote: Sun Aug 14, 2022 7:54 pm
It looks pretty clean to this greenhorn...
Keith did tell me today that there are many things in LUA that the AM developers did not implement in Air Manager. Maybe what you are trying to do is one of those omitted capabilities.
Naw, its just that I use C++ (Arduino flavoured) all the time. As said, I don't use the AM flashed arduinos of any kind, all direct comms for any hardware so never use the built in stuff at all.


as for placement, just lose both of those you have - comment all that out and put the code below in there instead. it should be logical ? he said haha

Code: Select all

-- create output
outp_id = hw_output_add("My output",false)

function input_change1(state)
    log(state)
    state = not state  
    log(state)
    hw_output_set(outp_id,state)
end

-- create input
position_1 = hw_input_add("My input 1", input_change1)
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#24 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 8:05 pm
Kaellis991 wrote: Sun Aug 14, 2022 7:54 pm
It looks pretty clean to this greenhorn...
Keith did tell me today that there are many things in LUA that the AM developers did not implement in Air Manager. Maybe what you are trying to do is one of those omitted capabilities.
Naw, its just that I use C++ (Arduino flavoured) all the time. As said, I don't use the AM flashed arduinos of any kind, all direct comms for any hardware so never use the built in stuff at all.


as for placement, just lose both of those you have - comment all that out and put tcode below in there instead.

Code: Select all

-- create output
outp_id = hw_output_add("My output",false)

function input_change1(state)
    log(state)
    state = not state  
    log(state)
end

-- create input
position_1 = hw_input_add("My input 1", input_change1)

Sorry Joe,

This is what I am getting now....each time I cover the sensor I get True False ...False True....True False....ad infinitum...the LED never activates now.
Oh well, maybe some other day it can get sorted out. It's time for me to grill up my dinner....
image.png

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#25 Post by jph »

Check the post just before your last, you are missing a line of code,... :shock: ;) the bit that controls the led.

Also, the true false false true true etc is correct for the log output as it is showing the entry and change state. Just remove the second log line if its confusing.

As for what happens then I have no idea as i dont have the sensor .. is the output pusled or constant? Anyway, the output in the console is correct for the 2 log lines, as said, remove one to make it easier to read.
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#26 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 8:33 pm Check the post just before your last, you are missing a line of code,... :shock: ;) the bit that controls the led.

Also, the true false false true true etc is correct for the log output as it is showing the entry and change state. Just remove the second log line if its confusing.

As for what happens then I have no idea as i dont have the sensor .. is the output pusled or constant? Anyway, the output in the console is correct for the 2 log lines, as said, remove one to make it easier to read.
Yes sir, I was just posting that I found that omission.

image.png

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#27 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 8:33 pm Check the post just before your last, you are missing a line of code,... :shock: ;) the bit that controls the led.

Also, the true false false true true etc is correct for the log output as it is showing the entry and change state. Just remove the second log line if its confusing.

As for what happens then I have no idea as i dont have the sensor .. is the output pusled or constant? Anyway, the output in the console is correct for the 2 log lines, as said, remove one to make it easier to read.
Joe,

It works as it should now. The LED lights up when I cover the sensor as it should. Thank you for all your expertise.

Don't you love it when a plan comes together?

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#28 Post by jph »

No worries :lol: , Glad u got sorted. Enjoy your dinner
Joe
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Confusion with ULN2803 and IR sensor power

#29 Post by Keith Baxter »

Hi,

Sorry Kirk. I had a short nap. Just add a not to swap the output state.

I see Joe assisted

Code: Select all

-- Create a new output 1
led1 = hw_output_add("My output led 1", true)

-- Create a new input 1
hw_input_add("My input 1",function(state)  
  hw_output_set(led1, not state)
end)
---------------------------------------------------------------
-- Create a new output 2
led2 = hw_output_add("My output led 2", true)

-- Create a new input 2
hw_input_add("My input 2",function(state)  
  hw_output_set(led2, not state)
end)
---------------------------------------------------------------
-- Create a new output 3
led3 = hw_output_add("My output led 3", true)

-- Create a new input 3
hw_input_add("My input 3",function(state)  
  hw_output_set(led3, not state)
end)
---------------------------------------------------------------
-- Create a new output 4
led4 = hw_output_add("My output led 4", true)

-- Create a new input 4
hw_input_add("My input 4",function(state)  
  hw_output_set(led4, not state)
end)
Keith
Last edited by Keith Baxter on Sun Aug 14, 2022 10:26 pm, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#30 Post by Kaellis991 »

Keith Baxter wrote: Sun Aug 14, 2022 9:35 pm Hi,

Sorry Kirk. I had a short nap. Just add a not to swap the output state.

I see Joe assisted

Code: Select all

-- Create a new output 1
led1 = hw_output_add("My output led1", true)

-- Create a new input 1
hw_input_add("My input 1",function(state)  
  hw_output_set(led1, not state)
end)
---------------------------------------------------------------
-- Create a new output 2
led2 = hw_output_add("My output led 2", true)

-- Create a new input 2
hw_input_add("My input 2",function(state)  
  hw_output_set(led2, not state)
end)
Keith
Yea Keith,
He helped out. It's all working now. The more I learn the more I dont know.

Post Reply