diy t-bar arduino - help me

5 posts / 0 new
Last post
Offline

Location

roma,
Italy
Joined: 11/08/2017
Posts: 5
diy t-bar arduino - help me
hi.
trying to make a t-bar with the arduino anologic door and a 10k slider. can someone help me? Do you have a sketch to give me a library and schematic?

 

 

imorrish's picture
Offline

Location

Wellington
New Zealand
Joined: 05/01/2015
Posts: 91
Presume you have the basics

Presume you have the basics of reading an analog value working?

This is the basic starting point 

https://www.arduino.cc/en/Tutorial/Potentiometer

I have only done it using a rotary encoder as per

See video

Trick is in normalising the value to be between 0 and 1 and also tracking the flip condition to start transition frame count in reverse direction if required.

Regards,

Ian

 

Offline

Location

roma,
Italy
Joined: 11/08/2017
Posts: 5
thank you! I used this code
thank you! I used this code but it does not w

 

Can you give me your code? My is a toy, simulates automatic fade. it isn't really.

 
 
 

 

imorrish's picture
Offline

Location

Wellington
New Zealand
Joined: 05/01/2015
Posts: 91
I use standar Firmata cketch

I use standar Firmata cketch in the Arduino and do all the processig in Windows PowerShell. Firmata is just a remote I/O protocol that exposes all the pins via the USB port using serial commands.

Just tested using a potentiometer connected to A5 using this PowerShll code running in ISE:

 
#Arduino interface
add-type -path 'C:\Users\imorrish\WindowsPowerShell\Solid.Arduino.dll'
$connection = New-Object Solid.Arduino.SerialConnection("COM4",[Solid.Arduino.SerialBaudRate]::Bps_57600)
$session = New-Object Solid.Arduino.ArduinoSession($connection, 2000)

#Get A5 pin mapping for this Arduino model
$mapping = $session.GetBoardAnalogMapping()
Start-Sleep -Milliseconds 2
$mapping.PinMappings[5] #19 for Uno board

#Convert analog number to 2 decimal place number between 0 and 1
function normalize($value, $min, $max) {
if($value -gt 412){$value=412}
if($value -lt 3){$value=0}
$normalized = [math]::Round(($value - $min) / ($max - $min),2)
return $normalized
}

#T-Bar
$Global:TbarLastFramPosition = 0
$Global:TransitionDirection = "normal"
#enable pin for reading
$session.SetDigitalPinMode(19,[Solid.Arduino.Firmata.PinMode]::AnalogInput)
$session.SetSamplingInterval(50)
$session.CreateAnalogStateMonitor(5)

# AnalogStateReceived event code
function analogevent($event){
$frame = normalize $event.value.Level 0 412
If($frame -ne $Global:TbarLastFramPosition){
$Global:TbarLastFramPosition = $frame
Write-Host $event.value.Level
if($Global:TransitionDirection -eq "normal"){
$Global:ME[0].TransitionPosition = $frame
Write-Host "Frame normal direction = $($frame)"
}
Else{
$Global:ME[0].TransitionPosition = (1-$frame)
Write-Host "Frame reverse direction = $($frame)"
}
if($frame -eq 0){
$Global:TransitionDirection = "normal"
Write-Host "Direction = normal"
}
elseif($frame -eq 1){
$Global:TransitionDirection = "reverse"
Write-Host "Direction = reverse"
}
}

}

#create event receiver
Unregister-Event -SourceIdentifier eventAnalogChange -ErrorAction SilentlyContinue #incase we are re-running the script
$ArduinoEvent = Register-ObjectEvent -InputObject $session -EventName AnalogStateReceived -SourceIdentifier eventAnalogChange -Action {analogevent($eventArgs)}

Video showing it working

See video
Offline

Location

roma,
Italy
Joined: 11/08/2017
Posts: 5
      thank you. I do not

 

 

 

thank you. I do not understand. In code I see: "add-type-path" C: \ Users \ imorrish \ WindowsPowerShell \ Solid.Arduino.dll "Where do I take it? What should i do: load the code on arduino? I have to use a simple 10k liner slider.