add small sim for audio output

This commit is contained in:
Julian Daube 2019-12-16 00:00:41 +01:00
parent 5253fdd58c
commit 61d34f3cdb
5 changed files with 1333 additions and 1063 deletions

View File

@ -174,26 +174,6 @@ X S 3 100 -200 100 U 50 50 1 1 P
ENDDRAW
ENDDEF
#
# Device_R_POT
#
DEF Device_R_POT RV 0 40 Y N 1 F N
F0 "RV" -175 0 50 V V C CNN
F1 "Device_R_POT" -100 0 50 V V C CNN
F2 "" 0 0 50 H I C CNN
F3 "" 0 0 50 H I C CNN
$FPLIST
Potentiometer*
$ENDFPLIST
DRAW
S 40 100 -40 -100 0 1 10 N
P 2 0 1 0 100 0 60 0 N
P 4 0 1 0 45 0 90 20 90 -20 45 0 F
X 1 1 0 150 50 D 50 50 1 1 P
X 2 2 150 0 50 L 50 50 1 1 P
X 3 3 0 -150 50 U 50 50 1 1 P
ENDDRAW
ENDDEF
#
# Device_R_Small
#
DEF Device_R_Small R 0 10 N N 1 F N
@ -266,6 +246,30 @@ X 1 1 0 -100 100 U 50 50 1 1 I
ENDDRAW
ENDDEF
#
# Switch_SW_DPDT_x2
#
DEF Switch_SW_DPDT_x2 SW 0 0 Y N 2 F N
F0 "SW" 0 170 50 H V C CNN
F1 "Switch_SW_DPDT_x2" 0 -200 50 H V C CNN
F2 "" 0 0 50 H I C CNN
F3 "" 0 0 50 H I C CNN
$FPLIST
SW*DPDT*
$ENDFPLIST
DRAW
C -80 0 20 0 0 0 N
C 80 -100 20 0 0 0 N
C 80 100 20 0 1 0 N
P 2 0 1 0 -60 10 65 90 N
X A 1 200 100 100 L 50 50 1 1 P
X B 2 -200 0 100 R 50 50 1 1 P
X C 3 200 -100 100 L 50 50 1 1 P
X A 4 200 100 100 L 50 50 2 1 P
X B 5 -200 0 100 R 50 50 2 1 P
X C 6 200 -100 100 L 50 50 2 1 P
ENDDRAW
ENDDEF
#
# Switch_SW_Push
#
DEF Switch_SW_Push SW 0 40 N N 1 F N

File diff suppressed because it is too large Load Diff

View File

@ -58,41 +58,41 @@ Wire Wire Line
$Comp
L Device:Battery BT1
U 1 1 5DF595DA
P 1050 1350
F 0 "BT1" H 1158 1396 50 0000 L CNN
F 1 "Battery" H 1158 1305 50 0000 L CNN
F 2 "Connector_Wire:SolderWirePad_1x02_P3.81mm_Drill1mm" V 1050 1410 50 0001 C CNN
F 3 "~" V 1050 1410 50 0001 C CNN
1 1050 1350
P 900 1650
F 0 "BT1" H 1008 1696 50 0000 L CNN
F 1 "Battery" H 1008 1605 50 0000 L CNN
F 2 "Connector_Wire:SolderWirePad_1x02_P3.81mm_Drill1mm" V 900 1710 50 0001 C CNN
F 3 "~" V 900 1710 50 0001 C CNN
1 900 1650
1 0 0 -1
$EndComp
$Comp
L power:VDD #PWR02
U 1 1 5DF59C81
P 1050 950
F 0 "#PWR02" H 1050 800 50 0001 C CNN
F 1 "VDD" H 1067 1123 50 0000 C CNN
F 2 "" H 1050 950 50 0001 C CNN
F 3 "" H 1050 950 50 0001 C CNN
1 1050 950
P 800 700
F 0 "#PWR02" H 800 550 50 0001 C CNN
F 1 "VDD" H 817 873 50 0000 C CNN
F 2 "" H 800 700 50 0001 C CNN
F 3 "" H 800 700 50 0001 C CNN
1 800 700
1 0 0 -1
$EndComp
Wire Wire Line
1050 950 1050 1150
900 1250 900 1450
$Comp
L power:GND #PWR04
U 1 1 5DF5AD77
P 1050 1750
F 0 "#PWR04" H 1050 1500 50 0001 C CNN
F 1 "GND" H 1055 1577 50 0000 C CNN
F 2 "" H 1050 1750 50 0001 C CNN
F 3 "" H 1050 1750 50 0001 C CNN
1 1050 1750
P 900 2050
F 0 "#PWR04" H 900 1800 50 0001 C CNN
F 1 "GND" H 905 1877 50 0000 C CNN
F 2 "" H 900 2050 50 0001 C CNN
F 3 "" H 900 2050 50 0001 C CNN
1 900 2050
1 0 0 -1
$EndComp
Wire Wire Line
1050 1550 1050 1750
Text Notes 1150 1250 0 50 ~ 0
900 1850 900 2050
Text Notes 1050 1500 0 50 ~ 0
2 AA = 3V to 1.8V
$Comp
L Connector:Conn_01x04_Female J1
@ -105,8 +105,6 @@ F 3 "~" H 5150 1400 50 0001 C CNN
1 5150 1400
1 0 0 -1
$EndComp
Wire Wire Line
4950 1400 4800 1400
Text GLabel 4050 1700 2 50 Input ~ 0
AUDIO
Wire Wire Line
@ -116,74 +114,74 @@ CALIBRATE
$Comp
L Switch:SW_Push SW1
U 1 1 5DF649D3
P 6400 2250
F 0 "SW1" V 6354 2398 50 0000 L CNN
F 1 "SW_Push" V 6445 2398 50 0000 L CNN
F 2 "Button_Switch_THT:SW_PUSH_6mm" H 6400 2450 50 0001 C CNN
F 3 "~" H 6400 2450 50 0001 C CNN
1 6400 2250
P 4450 6350
F 0 "SW1" V 4404 6498 50 0000 L CNN
F 1 "SW_Push" V 4495 6498 50 0000 L CNN
F 2 "Button_Switch_THT:SW_PUSH_6mm" H 4450 6550 50 0001 C CNN
F 3 "~" H 4450 6550 50 0001 C CNN
1 4450 6350
0 1 1 0
$EndComp
$Comp
L power:GND #PWR06
U 1 1 5DF65A25
P 6400 2600
F 0 "#PWR06" H 6400 2350 50 0001 C CNN
F 1 "GND" H 6405 2427 50 0000 C CNN
F 2 "" H 6400 2600 50 0001 C CNN
F 3 "" H 6400 2600 50 0001 C CNN
1 6400 2600
P 4450 6700
F 0 "#PWR06" H 4450 6450 50 0001 C CNN
F 1 "GND" H 4455 6527 50 0000 C CNN
F 2 "" H 4450 6700 50 0001 C CNN
F 3 "" H 4450 6700 50 0001 C CNN
1 4450 6700
1 0 0 -1
$EndComp
Wire Wire Line
6400 2450 6400 2600
4450 6550 4450 6700
$Comp
L power:VDD #PWR03
U 1 1 5DF66A21
P 6400 950
F 0 "#PWR03" H 6400 800 50 0001 C CNN
F 1 "VDD" H 6417 1123 50 0000 C CNN
F 2 "" H 6400 950 50 0001 C CNN
F 3 "" H 6400 950 50 0001 C CNN
1 6400 950
P 4450 5050
F 0 "#PWR03" H 4450 4900 50 0001 C CNN
F 1 "VDD" H 4467 5223 50 0000 C CNN
F 2 "" H 4450 5050 50 0001 C CNN
F 3 "" H 4450 5050 50 0001 C CNN
1 4450 5050
1 0 0 -1
$EndComp
Text GLabel 6250 2000 0 50 Input ~ 0
Text GLabel 4300 6100 0 50 Input ~ 0
CALIBRATE
$Comp
L Device:LED D1
U 1 1 5DF67AA5
P 6400 1400
F 0 "D1" V 6439 1283 50 0000 R CNN
F 1 "LED" V 6348 1283 50 0000 R CNN
F 2 "LED_THT:LED_D3.0mm" H 6400 1400 50 0001 C CNN
F 3 "~" H 6400 1400 50 0001 C CNN
1 6400 1400
P 4450 5500
F 0 "D1" V 4489 5383 50 0000 R CNN
F 1 "LED" V 4398 5383 50 0000 R CNN
F 2 "LED_THT:LED_D3.0mm" H 4450 5500 50 0001 C CNN
F 3 "~" H 4450 5500 50 0001 C CNN
1 4450 5500
0 -1 -1 0
$EndComp
$Comp
L Device:R_Small R1
U 1 1 5DF6A5BB
P 6400 1850
F 0 "R1" H 6459 1896 50 0000 L CNN
F 1 "330" H 6459 1805 50 0000 L CNN
F 2 "Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal" H 6400 1850 50 0001 C CNN
F 3 "~" H 6400 1850 50 0001 C CNN
1 6400 1850
P 4450 5950
F 0 "R1" H 4509 5996 50 0000 L CNN
F 1 "330" H 4509 5905 50 0000 L CNN
F 2 "Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal" H 4450 5950 50 0001 C CNN
F 3 "~" H 4450 5950 50 0001 C CNN
1 4450 5950
1 0 0 -1
$EndComp
Wire Wire Line
6400 950 6400 1250
4450 5050 4450 5350
Wire Wire Line
6400 1950 6400 2000
4450 6050 4450 6100
Wire Wire Line
6400 2000 6250 2000
4450 6100 4300 6100
Wire Wire Line
6400 1550 6400 1750
Connection ~ 6400 2000
4450 5650 4450 5850
Connection ~ 4450 6100
Wire Wire Line
6400 2000 6400 2050
Text Notes 6750 2000 0 50 ~ 0
4450 6100 4450 6150
Text Notes 4800 6100 0 50 ~ 0
MICROCONTROLLER \nshall be able to FLASH led \nif needed
Text Notes 5300 1400 0 50 ~ 0
TO TOUCHSCREEN
@ -215,8 +213,6 @@ Wire Wire Line
1550 3000 1550 3100
Text GLabel 950 3000 0 50 Input ~ 0
AUDIO
Wire Wire Line
950 3000 1000 3000
$Comp
L power:GND #PWR07
U 1 1 5DF71C06
@ -252,90 +248,83 @@ Connection ~ 1550 3000
$Comp
L Device:Q_NMOS_DGS Q1
U 1 1 5DF77FFB
P 1550 6400
F 0 "Q1" H 1756 6446 50 0000 L CNN
F 1 "Q_NMOS_DGS" H 1756 6355 50 0000 L CNN
F 2 "Package_TO_SOT_THT:TO-92" H 1750 6500 50 0001 C CNN
F 3 "~" H 1550 6400 50 0001 C CNN
1 1550 6400
P 1450 5000
F 0 "Q1" H 1656 5046 50 0000 L CNN
F 1 "Q_NMOS_DGS" H 1656 4955 50 0000 L CNN
F 2 "Package_TO_SOT_THT:TO-92" H 1650 5100 50 0001 C CNN
F 3 "~" H 1450 5000 50 0001 C CNN
1 1450 5000
1 0 0 -1
$EndComp
Wire Wire Line
1000 3000 1000 6400
Wire Wire Line
1000 6400 1350 6400
Connection ~ 1000 3000
Wire Wire Line
1000 3000 1100 3000
$Comp
L power:GND #PWR09
U 1 1 5DF79997
P 1650 6800
F 0 "#PWR09" H 1650 6550 50 0001 C CNN
F 1 "GND" H 1655 6627 50 0000 C CNN
F 2 "" H 1650 6800 50 0001 C CNN
F 3 "" H 1650 6800 50 0001 C CNN
1 1650 6800
P 1550 5400
F 0 "#PWR09" H 1550 5150 50 0001 C CNN
F 1 "GND" H 1555 5227 50 0000 C CNN
F 2 "" H 1550 5400 50 0001 C CNN
F 3 "" H 1550 5400 50 0001 C CNN
1 1550 5400
1 0 0 -1
$EndComp
$Comp
L Device:Speaker LS1
U 1 1 5DF7D3C5
P 2600 5900
F 0 "LS1" H 2770 5896 50 0000 L CNN
F 1 "Speaker" H 2770 5805 50 0000 L CNN
F 2 "Connector_Wire:SolderWirePad_1x02_P3.81mm_Drill1mm" H 2600 5700 50 0001 C CNN
F 3 "~" H 2590 5850 50 0001 C CNN
1 2600 5900
P 2500 4500
F 0 "LS1" H 2670 4496 50 0000 L CNN
F 1 "Speaker" H 2670 4405 50 0000 L CNN
F 2 "Connector_Wire:SolderWirePad_1x02_P3.81mm_Drill1mm" H 2500 4300 50 0001 C CNN
F 3 "~" H 2490 4450 50 0001 C CNN
1 2500 4500
1 0 0 -1
$EndComp
$Comp
L Device:D D2
U 1 1 5DF7A920
P 1650 5950
F 0 "D2" V 1604 6029 50 0000 L CNN
F 1 "D" V 1695 6029 50 0000 L CNN
F 2 "Diode_THT:D_DO-35_SOD27_P7.62mm_Horizontal" H 1650 5950 50 0001 C CNN
F 3 "~" H 1650 5950 50 0001 C CNN
1 1650 5950
P 1550 4550
F 0 "D2" V 1504 4629 50 0000 L CNN
F 1 "D" V 1595 4629 50 0000 L CNN
F 2 "Diode_THT:D_DO-35_SOD27_P7.62mm_Horizontal" H 1550 4550 50 0001 C CNN
F 3 "~" H 1550 4550 50 0001 C CNN
1 1550 4550
0 1 1 0
$EndComp
Wire Wire Line
2400 5900 2200 5900
2300 4500 2100 4500
Wire Wire Line
1650 6150 1650 6200
1550 4750 1550 4800
Wire Wire Line
2200 6000 2400 6000
2100 4600 2300 4600
Wire Wire Line
2200 6150 2200 6000
2100 4750 2100 4600
Wire Wire Line
2200 5900 2200 5750
2100 4500 2100 4350
Wire Wire Line
1650 6150 2200 6150
1550 4750 2100 4750
Wire Wire Line
1650 6600 1650 6800
1550 5200 1550 5400
Wire Wire Line
1650 6100 1650 6150
Connection ~ 1650 6150
Text Notes 2300 5700 0 50 ~ 0
1550 4700 1550 4750
Connection ~ 1550 4750
Text Notes 2200 4300 0 50 ~ 0
SIMPLE PULSE AMPLIFIER
$Comp
L Device:C_Small C2
U 1 1 5DF8C54D
P 1350 5950
F 0 "C2" H 1442 5996 50 0000 L CNN
F 1 "10u" H 1442 5905 50 0000 L CNN
F 2 "Capacitor_THT:C_Radial_D5.0mm_H5.0mm_P2.00mm" H 1350 5950 50 0001 C CNN
F 3 "~" H 1350 5950 50 0001 C CNN
1 1350 5950
P 1250 4550
F 0 "C2" H 1342 4596 50 0000 L CNN
F 1 "10u" H 1342 4505 50 0000 L CNN
F 2 "Capacitor_THT:C_Radial_D5.0mm_H5.0mm_P2.00mm" H 1250 4550 50 0001 C CNN
F 3 "~" H 1250 4550 50 0001 C CNN
1 1250 4550
1 0 0 -1
$EndComp
Wire Wire Line
1350 5850 1350 5750
1250 4450 1250 4350
Wire Wire Line
1350 6050 1350 6150
1250 4650 1250 4750
Wire Wire Line
1350 6150 1650 6150
1250 4750 1550 4750
$Comp
L Mechanical:MountingHole_Pad H1
U 1 1 5DF9AC6D
@ -412,63 +401,26 @@ Wire Wire Line
Connection ~ 10550 6900
Wire Wire Line
10550 6900 10400 6900
Wire Wire Line
4950 1500 4800 1500
Wire Wire Line
4800 1500 4800 1400
$Comp
L power:VDD #PWR011
U 1 1 5DFA42D5
P 4800 700
F 0 "#PWR011" H 4800 550 50 0001 C CNN
F 1 "VDD" H 4817 873 50 0000 C CNN
F 2 "" H 4800 700 50 0001 C CNN
F 3 "" H 4800 700 50 0001 C CNN
1 4800 700
1 0 0 -1
$EndComp
Wire Wire Line
4800 700 4800 1400
Connection ~ 4800 1400
Text Label 4500 1300 0 50 ~ 0
X
Text Label 4500 1400 0 50 ~ 0
Y
Wire Wire Line
4050 1800 3850 1800
$Comp
L power:VDD #PWR08
U 1 1 5DF79F75
P 1800 5050
F 0 "#PWR08" H 1800 4900 50 0001 C CNN
F 1 "VDD" H 1817 5223 50 0000 C CNN
F 2 "" H 1800 5050 50 0001 C CNN
F 3 "" H 1800 5050 50 0001 C CNN
1 1800 5050
P 1550 4000
F 0 "#PWR08" H 1550 3850 50 0001 C CNN
F 1 "VDD" H 1567 4173 50 0000 C CNN
F 2 "" H 1550 4000 50 0001 C CNN
F 3 "" H 1550 4000 50 0001 C CNN
1 1550 4000
1 0 0 -1
$EndComp
Connection ~ 1650 5750
Connection ~ 1550 4350
Wire Wire Line
1650 5750 1650 5800
1550 4350 1550 4400
Wire Wire Line
2200 5750 1650 5750
$Comp
L Device:R_POT RV1
U 1 1 5DFADF32
P 1650 5300
F 0 "RV1" V 1443 5300 50 0000 C CNN
F 1 "R_POT" V 1534 5300 50 0000 C CNN
F 2 "Potentiometer_THT:Potentiometer_Runtron_RM-065_Vertical" H 1650 5300 50 0001 C CNN
F 3 "~" H 1650 5300 50 0001 C CNN
1 1650 5300
0 1 1 0
$EndComp
2100 4350 1550 4350
Wire Wire Line
1800 5050 1800 5300
Wire Wire Line
1350 5750 1650 5750
Wire Wire Line
1650 5450 1650 5750
1250 4350 1550 4350
$Comp
L Device:C_Small C3
U 1 1 5DFB1F1D
@ -518,20 +470,38 @@ F 3 "" H 2500 3450 50 0001 C CNN
$EndComp
Wire Wire Line
2500 3300 2500 3450
Text GLabel 4900 1300 0 50 Input ~ 0
X
Wire Wire Line
4900 1300 4950 1300
Text GLabel 4900 1600 0 50 Input ~ 0
Y
3850 1300 4950 1300
Wire Wire Line
4900 1600 4950 1600
Text GLabel 3900 1300 2 50 Input ~ 0
Y
Text GLabel 3900 1400 2 50 Input ~ 0
X
3850 1400 4950 1400
Wire Wire Line
3900 1400 3850 1400
3850 1500 4950 1500
Wire Wire Line
3850 1300 3900 1300
3850 1600 4950 1600
$Comp
L Switch:SW_DPDT_x2 SW2
U 1 1 5DF65D1E
P 800 1050
F 0 "SW2" V 754 1198 50 0000 L CNN
F 1 "SW_DPDT_x2" V 845 1198 50 0000 L CNN
F 2 "Button_Switch_THT:SW_CuK_JS202011AQN_DPDT_Angled" H 800 1050 50 0001 C CNN
F 3 "~" H 800 1050 50 0001 C CNN
1 800 1050
0 1 1 0
$EndComp
Wire Wire Line
800 700 800 850
Text Notes 950 950 0 50 ~ 0
ON/OFF switch
Wire Wire Line
1550 4000 1550 4350
Wire Wire Line
1050 3000 1100 3000
Wire Wire Line
1050 3000 1050 5000
Wire Wire Line
950 3000 1050 3000
Wire Wire Line
1050 5000 1250 5000
Connection ~ 1050 3000
$EndSCHEMATC

75
sim/audio_amplifier.asc Normal file
View File

@ -0,0 +1,75 @@
Version 4
SHEET 1 2480 680
WIRE 784 -80 80 -80
WIRE 848 -80 784 -80
WIRE 896 -80 848 -80
WIRE 1008 -80 976 -80
WIRE 784 -32 784 -80
WIRE 848 -32 848 -80
WIRE 1008 -32 1008 -80
WIRE 688 96 256 96
WIRE 784 96 784 32
WIRE 848 96 848 32
WIRE 848 96 784 96
WIRE 1008 96 1008 48
WIRE 1008 96 848 96
WIRE 80 112 80 -80
WIRE 256 144 256 96
WIRE 848 176 848 96
WIRE 688 256 688 96
WIRE 800 256 688 256
WIRE 80 352 80 192
WIRE 256 352 256 224
WIRE 256 352 80 352
WIRE 848 352 848 272
WIRE 848 352 256 352
WIRE 1200 352 1200 256
WIRE 1200 352 848 352
WIRE 1600 352 1600 256
WIRE 1600 352 1200 352
WIRE 256 400 256 352
FLAG 256 400 0
SYMBOL voltage 80 96 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V1
SYMATTR Value {V}
SYMBOL diode 800 32 R180
WINDOW 0 24 64 Left 2
WINDOW 3 24 0 Left 2
SYMATTR InstName D1
SYMATTR Value 1N4148
SYMBOL res 992 -48 R0
SYMATTR InstName R2
SYMATTR Value 8
SYMBOL nmos 800 176 R0
SYMATTR InstName M1
SYMATTR Value AO6408
SYMBOL ind 992 -96 R90
WINDOW 0 5 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName L1
SYMATTR Value 10n
SYMBOL bv 256 128 R0
SYMATTR InstName B1
SYMATTR Value V=(0.5*sin(time*2*pi*(((time/1s)*5k+1k)))+0.5)*{V}
SYMBOL bv 1200 160 R0
SYMATTR InstName B2
SYMATTR Value V=V(n003)/{V}*2-1
SYMBOL bv 1600 160 R0
SYMATTR InstName B3
SYMATTR Value V=2*(I(R2)*(V(n001)-V(n004))/2W)-((I(R2)*(V(n001)-V(n004))/2W))
TEXT 1176 -144 Left 2 !.tran 1 uic
TEXT 1600 80 Left 2 !.wave "audio{V}.wav" 16 44.1k V(nc_02)
TEXT 1176 -168 Left 2 !.param V=1.9
TEXT 1600 104 Left 2 !.wave "ref{V}.wav" 16 44.1k V(nc_01)
TEXT 1120 80 Left 2 ;output to wave file
TEXT 1176 -112 Left 2 !.step param V list 1.6 3
LINE Normal 1776 64 1104 64 2
LINE Normal 2080 416 2080 64 2
LINE Normal 1104 416 1792 416 2
LINE Normal 1104 64 1104 416 2
LINE Normal 1104 64 1104 64 2
LINE Normal 2080 416 1792 416 2
LINE Normal 2080 64 1776 64 2
LINE Normal 2080 64 2080 64 2

View File

@ -1,38 +1,164 @@
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("\"setup\"");
uint8_t duty = 50; // start @ 50 % duty
float freq = 0.44; // start @ 440 hz
void set_duty(uint8_t d) {
duty = 100- d;
update_freq();
}
void set_freq(float f) {
freq = f;
update_freq();
}
void update_freq() {
uint16_t top = freq/0.440*142/2;
OCR2A = (top>0xFF)?0xFF:top;
OCR2B = top * duty / 100;
}
void setup_timer() {
// setup timer
update_freq();
TCCR2A= (1<<COM2B1) | (1<<WGM20);
TCCR2B= (1<<WGM22) | (1<<CS02); // 64 prescaler ( 5khz == TOP of 50, 1khz = 250 )
DDRD |= (1<<PD3);
}
void setup() {
setup_timer();
Serial.begin(9600);
Serial.println("setup complete");
interrupts();
}
#include <EEPROM.h>
class Panel {
int A,B;
int maxVals[2];
struct limits {
int touchThreas;
int minVals[2];
float range[2];
bool caldone;
} limits;
public:
Panel(int one, int two) : A(one), B(two) {
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
Panel():maxVals{1,1} {
// declare pins as input
DDRC &= ~((1<<PC0) | (1<<PC1) | (1<<PC2) | (1<<PC3));
EEPROM.get(0, limits);
}
int Y() {
digitalWrite(A, 1);
int result = analogRead(B);
digitalWrite(A, 0);
enum Axis {
X = 0,
Y
};
int operator()(Axis axis) {
int result = -1;
switch(axis) {
case X:
DDRC |= (1<<PC0) | (1<<PC2);
PORTC |= (1<<PC0) | (1<<PC1) ;
delay(1);
result = analogRead(A1);
break;
case Y:
DDRC |= (1<<PC1) | (1<<PC3);
PORTC |= (1<<PC0) | (1<<PC1) ;
delay(1);
result = analogRead(A2);
break;
}
PORTC = 0;
DDRC = 0;
return result;
}
int X() {
digitalWrite(B, 1);
int result = analogRead(A);
digitalWrite(B, 0);
return result;
float normalized(Axis axis) {
if (!limits.caldone)
return 0;
return ((*this)(axis)- limits.minVals[axis] )/ limits.range[axis];
}
void calibrate() {
static int state = 0;
switch(state++) {
case 0:
limits.touchThreas = (*this)(X) - 10;
break;
case 1:
limits.minVals[X] = (*this)(X);
limits.minVals[Y] = (*this)(Y);
break;
case 2:
maxVals[X] = (*this)(X);
maxVals[Y] = (*this)(Y);
default:
limits.range[X] = maxVals[X] - limits.minVals[X];
limits.range[Y] = maxVals[Y] - limits.minVals[Y];
limits.caldone = 1;
Serial.println("calibration complete");
EEPROM.put(0, limits);
state = 0;
}
}
operator bool() {
return ((*this)(X) < limits.touchThreas) || ((*this)(Y) < limits.touchThreas);
}
} panel(A0,A1);
} panel;
bool newline = true;
int sigmal = 0;
int mu = 0;
void loop() {
// put your main code here, to run repeatedly:
Serial.print(panel.X());
Serial.print("\t");
Serial.println(panel.Y());
delay(100);
if (panel) {
float x = panel.normalized(Panel::X),
y = panel.normalized(Panel::Y);
int n = x*12;
//float freq = powf(1.0595, n - 9) * 0.440;
float freq = powf(1.0905, n - 6) * 0.440;
// Serial.print(n);
// Serial.print("\t");
// Serial.println(freq);
//analogWrite(11, 255*panel.normalized(Panel::X));
set_freq(freq);
set_duty(y*100);
} else {
set_duty(100);
}
while(Serial.available()) {
char c = Serial.read();
if (newline && c == 'c') {
panel.calibrate();
newline = false;
} else if (!newline && c == '\n') {
newline = true;
}
}
//delay(100);
}