Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Arduino Codes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Medics
Arduino Codes
Commits
d11520bb
Commit
d11520bb
authored
1 month ago
by
mhby1g21
Browse files
Options
Downloads
Patches
Plain Diff
added smooth movement
parent
38f94011
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wifi-test/wifi-with-ui.ino
+62
-25
62 additions, 25 deletions
wifi-test/wifi-with-ui.ino
with
62 additions
and
25 deletions
wifi-test/wifi-with-ui.ino
+
62
−
25
View file @
d11520bb
...
...
@@ -16,10 +16,10 @@ Servo ring;
Servo
pinky
;
// Servo pins
const
int
indexPin
=
5
;
const
int
middlePin
=
4
;
const
int
ringPin
=
3
;
const
int
pinkyPin
=
2
;
const
int
indexPin
=
2
;
const
int
middlePin
=
3
;
const
int
ringPin
=
4
;
const
int
pinkyPin
=
5
;
// Current positions
int
indexPos
=
90
;
...
...
@@ -27,6 +27,16 @@ int middlePos = 90;
int
ringPos
=
90
;
int
pinkyPos
=
90
;
// Target positions for smooth movement
int
indexTarget
=
90
;
int
middleTarget
=
90
;
int
ringTarget
=
90
;
int
pinkyTarget
=
90
;
// Movement parameters
const
int
STEP_DELAY
=
5
;
// Delay between steps (ms)
const
int
STEP_SIZE
=
15
;
// Size of each step in degrees
void
setup
()
{
Serial
.
begin
(
9600
);
...
...
@@ -62,7 +72,29 @@ void setup() {
server
.
begin
();
}
void
moveServoSmooth
(
Servo
&
servo
,
int
&
currentPos
,
int
targetPos
)
{
if
(
currentPos
<
targetPos
)
{
for
(
int
pos
=
currentPos
;
pos
<=
targetPos
;
pos
+=
STEP_SIZE
)
{
servo
.
write
(
pos
);
currentPos
=
pos
;
delay
(
STEP_DELAY
);
}
}
else
{
for
(
int
pos
=
currentPos
;
pos
>=
targetPos
;
pos
-=
STEP_SIZE
)
{
servo
.
write
(
pos
);
currentPos
=
pos
;
delay
(
STEP_DELAY
);
}
}
}
void
loop
()
{
// Handle smooth servo movements
if
(
indexPos
!=
indexTarget
)
moveServoSmooth
(
index_f
,
indexPos
,
indexTarget
);
if
(
middlePos
!=
middleTarget
)
moveServoSmooth
(
middle
,
middlePos
,
middleTarget
);
if
(
ringPos
!=
ringTarget
)
moveServoSmooth
(
ring
,
ringPos
,
ringTarget
);
if
(
pinkyPos
!=
pinkyTarget
)
moveServoSmooth
(
pinky
,
pinkyPos
,
pinkyTarget
);
WiFiClient
client
=
server
.
available
();
if
(
client
)
{
...
...
@@ -95,6 +127,7 @@ void loop() {
client
.
println
(
".button:hover { background: #45a049; }"
);
client
.
println
(
".preset { background: #2196F3; }"
);
client
.
println
(
".reset { background: #f44336; }"
);
client
.
println
(
".wave { background: #ff9800; }"
);
client
.
println
(
"</style>"
);
client
.
println
(
"</head>"
);
client
.
println
(
"<body>"
);
...
...
@@ -126,6 +159,12 @@ void loop() {
client
.
println
(
"<button class='button reset' onclick='resetPositions()'>Reset to 90°</button>"
);
client
.
println
(
"</div>"
);
// Wave motion controls
client
.
println
(
"<div class='control-group'>"
);
client
.
println
(
"<h3>Wave Motion</h3>"
);
client
.
println
(
"<button class='button wave' onclick='startWave()'>Start Wave</button>"
);
client
.
println
(
"</div>"
);
// JavaScript
client
.
println
(
"<script>"
);
client
.
println
(
"function updateFinger(finger, angle) {"
);
...
...
@@ -141,6 +180,16 @@ void loop() {
client
.
println
(
"function resetPositions() {"
);
client
.
println
(
" allFingers(90);"
);
client
.
println
(
"}"
);
client
.
println
(
"function startWave() {"
);
client
.
println
(
" let fingers = ['index', 'middle', 'ring', 'pinky'];"
);
client
.
println
(
" let delay = 0;"
);
client
.
println
(
" fingers.forEach(finger => {"
);
client
.
println
(
" setTimeout(() => updateFinger(finger, 180), delay);"
);
client
.
println
(
" setTimeout(() => updateFinger(finger, 0), delay + 1000);"
);
client
.
println
(
" delay += 500;"
);
client
.
println
(
" });"
);
client
.
println
(
"}"
);
client
.
println
(
"</script>"
);
client
.
println
(
"</body></html>"
);
...
...
@@ -173,34 +222,22 @@ void processRequest(String request) {
String
command
=
request
.
substring
(
start
,
end
);
Serial
.
println
(
"Command: "
+
command
);
// Parse command and
move servo
s
// Parse command and
set target position
s
if
(
command
.
startsWith
(
"/index/"
))
{
int
angle
=
command
.
substring
(
7
).
toInt
();
angle
=
constrain
(
angle
,
0
,
180
);
index_f
.
write
(
angle
);
indexPos
=
angle
;
Serial
.
println
(
"Moving index to "
+
String
(
angle
));
indexTarget
=
constrain
(
command
.
substring
(
7
).
toInt
(),
0
,
180
);
Serial
.
println
(
"Moving index to "
+
String
(
indexTarget
));
}
else
if
(
command
.
startsWith
(
"/middle/"
))
{
int
angle
=
command
.
substring
(
8
).
toInt
();
angle
=
constrain
(
angle
,
0
,
180
);
middle
.
write
(
angle
);
middlePos
=
angle
;
Serial
.
println
(
"Moving middle to "
+
String
(
angle
));
middleTarget
=
constrain
(
command
.
substring
(
8
).
toInt
(),
0
,
180
);
Serial
.
println
(
"Moving middle to "
+
String
(
middleTarget
));
}
else
if
(
command
.
startsWith
(
"/ring/"
))
{
int
angle
=
command
.
substring
(
6
).
toInt
();
angle
=
constrain
(
angle
,
0
,
180
);
ring
.
write
(
angle
);
ringPos
=
angle
;
Serial
.
println
(
"Moving ring to "
+
String
(
angle
));
ringTarget
=
constrain
(
command
.
substring
(
6
).
toInt
(),
0
,
180
);
Serial
.
println
(
"Moving ring to "
+
String
(
ringTarget
));
}
else
if
(
command
.
startsWith
(
"/pinky/"
))
{
int
angle
=
command
.
substring
(
7
).
toInt
();
angle
=
constrain
(
angle
,
0
,
180
);
pinky
.
write
(
angle
);
pinkyPos
=
angle
;
Serial
.
println
(
"Moving pinky to "
+
String
(
angle
));
pinkyTarget
=
constrain
(
command
.
substring
(
7
).
toInt
(),
0
,
180
);
Serial
.
println
(
"Moving pinky to "
+
String
(
pinkyTarget
));
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment