B4R Question led library

ideamaker

Member
In this way, we don't need to know what the single chip microcomputer has done, and we just need to connect wires. Actually, I can't use B4R. I tried to write a library for the first time. This library is incomplete and needs to be modified, but it is not clear what went wrong. My English is poor, so I have to rely on the browser to translate. Therefore, there are many incomprehensible places in the tutorial found.
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Dim myled As LED
    Dim timer1 As Timer
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    myled.Initialize(13,True)
    
    Log("AppStart")
    
    timer1.Initialize("Timer1_Tick",100)
    timer1.Enabled = True
    
End Sub

Private Sub Timer1_Tick
    
    myled.on()
    Delay(300)
    myled.off()
    Delay(300)   
    
End Sub
 

Attachments

  • addLibraries.zip
    1.4 KB · Views: 236

ideamaker

Member
1. Why do you need a library for this??? Use Pin instead of LED.
2. It is a mistake to use Delay to control the program flow. Use Timer or CallSubPlus.
The purpose of compiling this library is to make it easier for children to learn. They only need to know which foot led connects, and then led.on or led.off can control them. I used to teach Lego. Programming is too difficult for children, so I want to make it easier for them to get started.
 
Upvote 0

ideamaker

Member
1. Why do you need a library for this??? Use Pin instead of LED.
2. It is a mistake to use Delay to control the program flow. Use Timer or CallSubPlus.
Hello, I want to ask a question. I want to get the return value, but these lines of code can't generate xml normally
B4X:
    boolean B4RLED::getState(){
        if(digitalRead(pin) == HIGH){
            return true;
        }else{
            return false;   
        }
    }

    Byte B4RLED::getPin(){
        return pin;
    }
 
Upvote 0

ideamaker

Member
You are wasting your time with this library.

If you think that calling Pin.DigitialWrite is too difficult then add these two subs:
B4X:
Sub LedOn (Pin As Pin)
    Pin.DigitalWrite(True)
End Sub

Sub LedOff (Pin As Pin)
    Pin.DigitalWrite(False)
End Sub
I just want to learn how to package the B4R library, and I can't understand some of the tutorials I found. So I plan to try to package a minimum library by myself, which is convenient for my students to use
 
Upvote 0
Top