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
38f94011
Commit
38f94011
authored
2 months ago
by
mhby1g21
Browse files
Options
Downloads
Patches
Plain Diff
added some ui to new file
parent
fc53ad0a
No related branches found
Branches containing commit
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
+220
-0
220 additions, 0 deletions
wifi-test/wifi-with-ui.ino
with
220 additions
and
0 deletions
wifi-test/wifi-with-ui.ino
0 → 100644
+
220
−
0
View file @
38f94011
#include
<WiFiNINA.h>
#include
<Servo.h>
// WiFi credentials
const
char
ssid
[]
=
"SOTON-IoT"
;
const
char
pass
[]
=
"pUguZXWtBDzl"
;
int
status
=
WL_IDLE_STATUS
;
// Server settings
WiFiServer
server
(
80
);
// Create servo objects
Servo
index_f
;
Servo
middle
;
Servo
ring
;
Servo
pinky
;
// Servo pins
const
int
indexPin
=
5
;
const
int
middlePin
=
4
;
const
int
ringPin
=
3
;
const
int
pinkyPin
=
2
;
// Current positions
int
indexPos
=
90
;
int
middlePos
=
90
;
int
ringPos
=
90
;
int
pinkyPos
=
90
;
void
setup
()
{
Serial
.
begin
(
9600
);
// Initialize servos
index_f
.
attach
(
indexPin
);
middle
.
attach
(
middlePin
);
ring
.
attach
(
ringPin
);
pinky
.
attach
(
pinkyPin
);
// Set initial positions
index_f
.
write
(
indexPos
);
middle
.
write
(
middlePos
);
ring
.
write
(
ringPos
);
pinky
.
write
(
pinkyPos
);
// Check for WiFi module
if
(
WiFi
.
status
()
==
WL_NO_MODULE
)
{
Serial
.
println
(
"Communication with WiFi module failed!"
);
while
(
true
);
}
// Attempt to connect to WiFi network
while
(
status
!=
WL_CONNECTED
)
{
Serial
.
print
(
"Attempting to connect to Network: "
);
Serial
.
println
(
ssid
);
status
=
WiFi
.
begin
(
ssid
,
pass
);
delay
(
10000
);
}
Serial
.
println
(
"Connected to wifi"
);
printWiFiStatus
();
server
.
begin
();
}
void
loop
()
{
WiFiClient
client
=
server
.
available
();
if
(
client
)
{
Serial
.
println
(
"New client connected"
);
String
request
=
""
;
boolean
currentLineIsBlank
=
true
;
while
(
client
.
connected
())
{
if
(
client
.
available
())
{
char
c
=
client
.
read
();
request
+=
c
;
if
(
c
==
'\n'
&&
currentLineIsBlank
)
{
client
.
println
(
"HTTP/1.1 200 OK"
);
client
.
println
(
"Content-Type: text/html"
);
client
.
println
(
"Connection: close"
);
client
.
println
();
// Send HTML page
client
.
println
(
"<!DOCTYPE html>"
);
client
.
println
(
"<html>"
);
client
.
println
(
"<head>"
);
client
.
println
(
"<title>Robotic Hand Control</title>"
);
client
.
println
(
"<meta name='viewport' content='width=device-width, initial-scale=1'>"
);
client
.
println
(
"<style>"
);
client
.
println
(
"body { font-family: Arial; margin: 20px; }"
);
client
.
println
(
".control-group { margin-bottom: 20px; background: #f5f5f5; padding: 15px; border-radius: 8px; }"
);
client
.
println
(
".slider { width: 200px; margin: 10px 0; }"
);
client
.
println
(
".button { background: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; margin: 5px; }"
);
client
.
println
(
".button:hover { background: #45a049; }"
);
client
.
println
(
".preset { background: #2196F3; }"
);
client
.
println
(
".reset { background: #f44336; }"
);
client
.
println
(
"</style>"
);
client
.
println
(
"</head>"
);
client
.
println
(
"<body>"
);
client
.
println
(
"<h1>Robotic Hand Control Panel</h1>"
);
// Individual finger controls
String
fingers
[]
=
{
"Index"
,
"Middle"
,
"Ring"
,
"Pinky"
};
int
positions
[]
=
{
indexPos
,
middlePos
,
ringPos
,
pinkyPos
};
String
endpoints
[]
=
{
"index"
,
"middle"
,
"ring"
,
"pinky"
};
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
client
.
println
(
"<div class='control-group'>"
);
client
.
println
(
"<h3>"
+
fingers
[
i
]
+
" Finger</h3>"
);
client
.
println
(
"<input type='range' class='slider' min='0' max='180' value='"
+
String
(
positions
[
i
])
+
"' "
);
client
.
println
(
"oninput='updateFinger(
\"
"
+
endpoints
[
i
]
+
"
\"
, this.value)'>"
);
client
.
println
(
"<span>Position: "
+
String
(
positions
[
i
])
+
"°</span>"
);
client
.
println
(
"<br>"
);
client
.
println
(
"<button class='button' onclick='updateFinger(
\"
"
+
endpoints
[
i
]
+
"
\"
, 0)'>Close</button>"
);
client
.
println
(
"<button class='button' onclick='updateFinger(
\"
"
+
endpoints
[
i
]
+
"
\"
, 180)'>Open</button>"
);
client
.
println
(
"</div>"
);
}
// Preset controls
client
.
println
(
"<div class='control-group'>"
);
client
.
println
(
"<h3>Preset Controls</h3>"
);
client
.
println
(
"<button class='button preset' onclick='allFingers(0)'>Close All</button>"
);
client
.
println
(
"<button class='button preset' onclick='allFingers(180)'>Open All</button>"
);
client
.
println
(
"<button class='button reset' onclick='resetPositions()'>Reset to 90°</button>"
);
client
.
println
(
"</div>"
);
// JavaScript
client
.
println
(
"<script>"
);
client
.
println
(
"function updateFinger(finger, angle) {"
);
client
.
println
(
" fetch('/' + finger + '/' + angle);"
);
client
.
println
(
"}"
);
client
.
println
(
"function allFingers(angle) {"
);
client
.
println
(
" ['index', 'middle', 'ring', 'pinky'].forEach(finger => {"
);
client
.
println
(
" updateFinger(finger, angle);"
);
client
.
println
(
" });"
);
client
.
println
(
"}"
);
client
.
println
(
"function resetPositions() {"
);
client
.
println
(
" allFingers(90);"
);
client
.
println
(
"}"
);
client
.
println
(
"</script>"
);
client
.
println
(
"</body></html>"
);
break
;
}
if
(
c
==
'\n'
)
{
currentLineIsBlank
=
true
;
}
else
if
(
c
!=
'\r'
)
{
currentLineIsBlank
=
false
;
}
}
}
// Process the request
if
(
request
.
indexOf
(
"GET /"
)
!=
-
1
)
{
processRequest
(
request
);
}
delay
(
10
);
client
.
stop
();
Serial
.
println
(
"Client disconnected"
);
}
}
void
processRequest
(
String
request
)
{
int
start
=
request
.
indexOf
(
"GET "
)
+
4
;
int
end
=
request
.
indexOf
(
" HTTP"
);
if
(
start
!=
-
1
&&
end
!=
-
1
)
{
String
command
=
request
.
substring
(
start
,
end
);
Serial
.
println
(
"Command: "
+
command
);
// Parse command and move servos
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
));
}
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
));
}
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
));
}
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
));
}
}
}
void
printWiFiStatus
()
{
Serial
.
print
(
"SSID: "
);
Serial
.
println
(
WiFi
.
SSID
());
IPAddress
ip
=
WiFi
.
localIP
();
Serial
.
print
(
"IP Address: "
);
Serial
.
println
(
ip
);
long
rssi
=
WiFi
.
RSSI
();
Serial
.
print
(
"Signal strength (RSSI):"
);
Serial
.
print
(
rssi
);
Serial
.
println
(
" dBm"
);
}
\ No newline at end of file
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