Title: | A Microcontroller Interface |
---|---|
Description: | Functions for connecting to and interfacing with an 'Arduino' or similar device. Functionality includes uploading of sketches, setting and reading digital and analog pins, and rudimentary servo control. This project is not affiliated with the 'Arduino' company, <https://www.arduino.cc/>. |
Authors: | Chris Suh, Peter Hoff |
Maintainer: | Peter Hoff <[email protected]> |
License: | GPL-3 |
Version: | 0.2 |
Built: | 2024-11-22 03:04:41 UTC |
Source: | https://github.com/pdhoff/rduino |
Get the value of an analog pin
getApin(pin)
getApin(pin)
pin |
the number of the pin to get (integer) |
the value of the pin.
## Not run: rduinoConnect() # set position of servo to position of potentiometer off<-getDpin(4) while (!off) { angle<-getApin(5) angle<- 1.68 * angle + 575 setServo(9,angle) off<-getDpin(4) } offServo() rduinoClose() ## End(Not run)
## Not run: rduinoConnect() # set position of servo to position of potentiometer off<-getDpin(4) while (!off) { angle<-getApin(5) angle<- 1.68 * angle + 575 setServo(9,angle) off<-getDpin(4) } offServo() rduinoClose() ## End(Not run)
Get the value of a digital pin
getDpin(pin)
getDpin(pin)
pin |
the number of the pin to get (integer) |
the binary value of the pin.
## Not run: rduinoConnect() # LED remains on until button is pressed setDpin(5,1) isPressed<-getDpin(4) while (!isPressed){ isPressed<-getDpin(4) } setDpin(5,0) rduinoClose() ## End(Not run)
## Not run: rduinoConnect() # LED remains on until button is pressed setDpin(5,1) isPressed<-getDpin(4) while (!isPressed){ isPressed<-getDpin(4) } setDpin(5,0) rduinoClose() ## End(Not run)
Turns off the square wave generated by onSignal
offSignal()
offSignal()
Activate a servo and set a value
onServo(pin, value)
onServo(pin, value)
pin |
the number of the pin connected to the servo |
value |
value to set for the servo |
## Not run: rduinoConnect() # set position of servo to position of potentiometer off<-getDpin(4) while (!off) { angle<-getApin(5) angle<- 1.68 * angle + 575 setServo(9,angle) off<-getDpin(4) } offServo() rduinoClose() ## End(Not run)
## Not run: rduinoConnect() # set position of servo to position of potentiometer off<-getDpin(4) while (!off) { angle<-getApin(5) angle<- 1.68 * angle + 575 setServo(9,angle) off<-getDpin(4) } offServo() rduinoClose() ## End(Not run)
On Signal Generate a square wave, from 1Hz to 31.25kHz, with resolution of 16us
onSignal(freq, dutyCycle1, dutyCycle2)
onSignal(freq, dutyCycle1, dutyCycle2)
freq |
the frequency of the wave, in Hz |
dutyCycle1 |
the percentage of time that pin 9 should spend at HIGH |
dutyCycle2 |
the percentage of time that pin 10 should spend at HIGH |
Disconnect a previously connected Arduino or similar device
rduinoClose()
rduinoClose()
Make a serial connection to an Arduino or similar device
rduinoConnect(baud = 38400, mode = "n,8,1", upload = FALSE, arduino = NULL, sdPin = 8)
rduinoConnect(baud = 38400, mode = "n,8,1", upload = FALSE, arduino = NULL, sdPin = 8)
baud |
baud rate |
mode |
communication mode |
upload |
if TRUE, upload the ino file to the device |
arduino |
command used to run arduino as a shell command including the path This function does two things - uploads a .ino file to an Arduino, and
acts as a wrapper for the |
## Not run: rduinoConnect() rduinoClose() ## End(Not run)
## Not run: rduinoConnect() rduinoClose() ## End(Not run)
Samples in as quickly as possible from given pin for specified duration
rduinoSample(readPin, time)
rduinoSample(readPin, time)
readPin |
the analog pin to read in from |
time |
the length of time (ms) that the Arduino should read data for |
Set a analog pin to on or off
setApin(pin, value)
setApin(pin, value)
pin |
the number of the pin to set (integer) |
value |
the value to which to set the pin (real) |
## Not run: rduinoConnect() # gradually increase intensity of LED for (i in seq(1,256,by=5)) { setApin(11,i) Sys.sleep(0.05) } rduinoClose() ## End(Not run)
## Not run: rduinoConnect() # gradually increase intensity of LED for (i in seq(1,256,by=5)) { setApin(11,i) Sys.sleep(0.05) } rduinoClose() ## End(Not run)
Set a digital pin to on or off
setDpin(pin, value)
setDpin(pin, value)
pin |
the number of the pin to set (integer) |
value |
the value to which to set the pin (binary) |
## Not run: rduinoConnect() # flash LED rapidly for (i in 0:9) { setDpin(8,1) Sys.sleep(0.05) setDpin(8,0) Sys.sleep(0.05) } rduinoClose() ## End(Not run)
## Not run: rduinoConnect() # flash LED rapidly for (i in 0:9) { setDpin(8,1) Sys.sleep(0.05) setDpin(8,0) Sys.sleep(0.05) } rduinoClose() ## End(Not run)