B4R Question How to use translate for B4R

Peter Simpson

Expert
Licensed User
Longtime User
Good morning all,
I have the following line of code in some Arduino IDE code, I've looked at rWire and I still do not understand it, I'm absolutely none the wiser.

B4X:
attachInterrupt(2, zero_crosss_int, RISING);

So the interrupt is on pin 2, and when that pin goes from LOW to HIGH it calls a sub named zero_crosss_int, but how exactly do I translate this line into actual usable code that works in B4R?

Thank you...
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Start with this:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private pin2 As Pin
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   pin2.Initialize(2, pin2.MODE_INPUT)
   pin2.AddListener("pin2_StateChanged")
End Sub

Sub Pin2_StateChanged (State As Boolean)
   If State = True Then
     'rising code
   End If
End Sub
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Thank you @Erel but I did that 3 or 4 days ago and got absolutly no where, obviously I'm missing something rather simple. It's probably another part of my code. I'll rewrite it all as the above code has already been tried. I was convinced that it was that part of the code but after seeing the above code, it's obviously another issue.

I'll try again tomorrow, as I'm too tired to be doing this right now and not in the right frame of mind either.

Thank you again as anyway, cheers...
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
On/off or high/low states in electronics are not that simple... For some pins (digital I/O) a simple "no voltage" floating state does not trigger a zero, but rather an undefined state... You may need a pull up or pull down resistor, according to your schematics needs
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Hiya guys,
Thank you for your feedback guys.

It was connected onto pin 2 (an interrupt pin) of an Uno compatible board @Erel. I've now scrapped the project for the moment, It wasn't too big so I'll rewrite the code again in a few days time. I usually do that as I find that I will have a new perspective things.

@Cableguy I have to catch the zero crossing state when the pin goes from LOW to HIGH (RISING) to know exactly when to trigger (open/close) a Triac. Just like in B4A, I will probably get it in a few days time when I decide to rewrite the code from scratch again.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Hello @Cableguy, it appears that you are smarter than the average Bear, as Yogi Bear would say himself ;)

Yes I'm playing about with an AV dimmer. I've actually got 2 different types of dimmers, I actually own an Arduino with a built in dimmer controller circuit too, but I may have to give that one a miss.

The article link in your post is very interesting indeed, just watched the video on that page.

I'm looking to use dimmers in my office, but it's not as easy as first though. I'm also looking for actual touch sensitive dimmer controllers that also allow me to interact via software, so that I can use either the touch buttons on the light panel or an Android app that I code myself.

I'm just about to start on the project again (from the beginning), I believe I now know where I went wrong, so wish me luck :)

Here is the AC Dimmer control board that I'm currently working with.
The current load is 1A constant or 5A peak for short periods of time. For a constant 2A load I just need to add a heat sink to the triac.

IMG_20170314_110941.jpg
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
It sounds like a cool project...
Don't forget to share once finished!
 
Upvote 0
Top