Home ArduinoB4R B4R and Easy Module Shield examples for the Arduino part 1

B4R and Easy Module Shield examples for the Arduino part 1

I like the Easy Module Shield shield for Arduino’s, its a nice low cost option with a variety of features. here is a picture of the shield

Multi purpose Shield V1

Multi purpose Shield V1

This shield has the following

  • DHT11 temperature and humidity sensor
  • LM35 temperature sensor
  • A photoresistor
  • RGB LED
  • Two LEDS
  • IR receiver
  • Two push buttons
  • A buzzer
  • And a potentiometer

 

2 LED example

[codesyntax lang=”qbasic”]

Sub Process_Globals
	Public Serial1 As Serial
	Private Timer1 As Timer
	Private pin13 As Pin
	Private pin12 As Pin
End Sub

Private Sub AppStart
	Serial1.Initialize(115200)
	Log("AppStart")
	pin13.Initialize(13, pin13.MODE_OUTPUT)
	pin12.Initialize(12, pin12.MODE_OUTPUT)
	Timer1.Initialize("Timer1_Tick", 1000) '1000ms = 1 second
	Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick
	Dim currentState As Boolean = pin13.DigitalRead
	Log("CurrentState: ", currentState)
	Dim NewState As Boolean = Not(currentState)
	Log("NewState: ", NewState)
	pin13.DigitalWrite(NewState)
	pin12.DigitalWrite(NewState)
End Sub

[/codesyntax]

 

Button example

[codesyntax lang=”qbasic”]

#Region Project Attributes
	#AutoFlushLogs: True
	#CheckArrayBounds: True
	#StackBufferSize: 300
#End Region

Sub Process_Globals
	Public Serial1 As Serial
	Private pinButton As Pin	'pin for the button
	Private pinLED13 As Pin	'pin for LED 13 on the Arduino
End Sub

Private Sub AppStart
	Serial1.Initialize(115200)
	Log("AppStart")
	
	pinLED13.Initialize(12, pinLED13.MODE_OUTPUT)
	pinButton.Initialize(2, pinButton.MODE_INPUT_PULLUP) 'Using the internal pull up resistor to prevent the pin from floating.
	pinButton.AddListener("pinButton_StateChanged")
End Sub

Sub pinButton_StateChanged (State As Boolean)
	Log("State: ", State)
	'state will be False when the button is clicked because of the PULLUP mode.
	pinLED13.DigitalWrite(Not(State))
End Sub

[/codesyntax]

 

RGB LED example

[codesyntax lang=”qbasic”]

#Region Project Attributes
	#AutoFlushLogs: True
	#CheckArrayBounds: True
	#StackBufferSize: 300
#End Region

Sub Process_Globals
	Public Serial1 As Serial
	Private rpin, gpin, bpin As Pin
End Sub

Private Sub AppStart
	Serial1.Initialize(115200)
	Log("AppStart")
	rpin.Initialize(9, rpin.MODE_OUTPUT)
	gpin.Initialize(10, rpin.MODE_OUTPUT)
	bpin.Initialize(11, rpin.MODE_OUTPUT)
	'red
	rpin.AnalogWrite(255)
	gpin.AnalogWrite(0)
	bpin.AnalogWrite(0)
	Delay(500)
	'green
	rpin.AnalogWrite(0)
	gpin.AnalogWrite(255)
	bpin.AnalogWrite(0)
	Delay(500)
	'blue
	rpin.AnalogWrite(0)
	gpin.AnalogWrite(0)
	bpin.AnalogWrite(255)
	Delay(500)
End Sub

[/codesyntax]

 

Potentiometer example

[codesyntax lang=”qbasic”]

Sub Process_Globals
	Public Serial1 As Serial
	Private POTPin As Pin                            'Output pin connected from the LDR
	Private POTPinNumber As Byte = 0x00   'Pin number used is A0 (Analog)
	Private MeasureTimer As Timer                           'Timer for the sensor measurement
	Private MeasureTimerInterval As ULong  = 1        'Timerinterval in seconds
End Sub

Private Sub AppStart
	Serial1.Initialize(115200)
	Log("AppStart - POTPIN ", POTPinNumber, " read every ", MeasureTimerInterval, " seconds")
	'Init the pin with POT connected
	POTPin.Initialize(POTPinNumber, POTPin.MODE_OUTPUT)
	'Init the timer
	MeasureTimer.Initialize("MeasureTimer_Tick", MeasureTimerInterval * 1000)
	'Start the timer
	MeasureTimer.Enabled = True
End Sub

'Handle the timer ticks
Private Sub MeasureTimer_Tick
	'Read the current state of the pin
	Dim rawreading As UInt = POTPin.AnalogRead
	'Convert rawvoltage To celsius And fahrenheit
	Log("Raw reading: ", rawreading)
End Sub

[/codesyntax]

Look at the log window

********************* PROGRAM STARTING ****************
AppStart – POTPIN 0 read every 1 seconds
Raw reading: 632
Raw reading: 632
Raw reading: 634
Raw reading: 38
Raw reading: 0
Raw reading: 625
Raw reading: 1023
Raw reading: 1023
Raw reading: 447

 

more examples to come in the next part

You may also like