So first off please bear with me, this is my first time working with any of this. I was able to write a simple python code that could send info to the arduino and control its servo:
def main(inp):
import serial
ser = serial.Serial("/dev/cu.usbmodemfa131") # open arduino serial port
ser.write(inp) # write a string
ser.close() # close port
and i was able to make an html/javascript file with a number slider that i can open with node.js on my computer. my first thought was to perhaps have this python script called every time the user changed the number on the slider and therefore have the arduino's servo move accordingly, however this seemed hard to do in javascript. how can i have the user inputs on the website write to the arduino's serial port?
this is the html file, the slider was made using jquery.
<html lang="en">
<head>
<meta charset="utf-8">
<title>Slider Demo</title>
<link rel="stylesheet" href="jquery-ui.min.css">
<style>#slider { margin: 50px; } </style>
<script src="external/jquery/jquery.js"></script>
<script src="jquery-ui.min.js"></script>
</head>
<body>
<div class="center" id="slider"></div>
<center>
<div id="slider-result">90</div>
</center>
<input type="hidden" id="hidden"/>
<script>
$( "#slider" ).slider({
animate: true,
range: "min",
value: 90,
min: 0,
max: 180,
step: 1,
})
//this gets a live reading of the value and prints it on the page
slide: function( event, ui ) {
$( "#slider-result" ).html( ui.value );
},
//this updates the hidden form field so we can submit the data using a form
change: function(event, ui) {
$('#hidden').attr('value', ui.value);
}
});
</script>
</body>
</html>