Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hackEns
TouchlessTracking
Commits
92d85d46
Commit
92d85d46
authored
Sep 30, 2013
by
Phyks
Browse files
Initial commit : 1 electrode
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
main.py
0 → 100755
View file @
92d85d46
#!/bin/env python
import
serial
import
pygame
ser
=
serial
.
Serial
(
"/dev/ttyACM0"
,
115200
)
pygame
.
init
()
size
=
width
,
height
=
640
,
480
black
=
0
,
0
,
0
screen
=
pygame
.
display
.
set_mode
(
size
)
background
=
pygame
.
Surface
(
screen
.
get_size
())
background
=
background
.
convert
()
background
.
fill
(
black
)
try
:
ser
.
open
()
except
Exception
,
e
:
print
(
"Error while opening serial port : "
+
str
(
e
))
if
ser
.
isOpen
():
ser
.
flushInput
()
ser
.
flushOutput
()
maximum
=
-
1.
minimum
=
-
1.
print
(
"Calibration"
)
screen
.
blit
(
background
,
(
0
,
0
))
pygame
.
display
.
flip
()
for
i
in
range
(
50
)
:
line
=
float
(
ser
.
readline
())
if
line
<
minimum
or
minimum
<
0
:
minimum
=
line
if
line
>
maximum
:
maximum
=
line
print
(
"Go"
)
while
True
:
line
=
float
(
ser
.
readline
())
background
.
fill
((
int
(
255.
*
(
line
-
minimum
)
/
(
maximum
-
minimum
)),
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
pygame
.
display
.
flip
()
ser
.
close
()
touchless_tracking/touchless_tracking.ino
0 → 100644
View file @
92d85d46
#define resolution 8
#define mains 50 // 60: north america, japan; 50: most other places
#define refresh 2 * 1000000 / mains
// Counter for the timer
extern
volatile
unsigned
long
timer0_overflow_count
;
/* === */
/* ??? */
void
startTimer
()
{
timer0_overflow_count
=
0
;
TCNT0
=
0
;
}
unsigned
long
checkTimer
()
{
return
((
timer0_overflow_count
<<
8
)
+
TCNT0
)
<<
2
;
}
long
time
(
int
pin
,
byte
mask
)
{
unsigned
long
count
=
0
,
total
=
0
;
while
(
checkTimer
()
<
refresh
)
{
// pinMode is about 6 times slower than assigning
// DDRB directly, but that pause is important
pinMode
(
pin
,
OUTPUT
);
PORTB
=
0
;
pinMode
(
pin
,
INPUT
);
while
((
PINB
&
mask
)
==
0
)
count
++
;
total
++
;
}
startTimer
();
return
(
count
<<
resolution
)
/
total
;
}
/* ??? */
/* === */
void
setup
()
{
// Initialize serial communication
Serial
.
begin
(
115200
);
// INPUT on pin 8
pinMode
(
8
,
INPUT
);
// Start timer
startTimer
();
}
void
loop
()
{
// Print output to serial in decimal
Serial
.
print
(
time
(
8
,
B00000001
),
DEC
);
Serial
.
print
(
" "
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment