-
Notifications
You must be signed in to change notification settings - Fork 0
/
08.1.1_Softlight.fs
43 lines (33 loc) · 970 Bytes
/
08.1.1_Softlight.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /usr/bin/env gforth
\ Forget and reload definitions if this file is re-included.
[ifdef] -SOFTLIGHT
-SOFTLIGHT
[endif]
marker -SOFTLIGHT
include wiringPi.fs
wiringPiSetup drop
variable fd_
variable address
variable cmd
variable chn
variable adcValue
fvariable voltage
0 constant ledPin
wiringPiSetup drop
0 chn !
0x84 cmd !
0x4b address !
ledPin 0 100 softPwmCreate
address @ wiringPiI2CSetup fd_ ! \ looking for ADS7830
fd_ @ 0 wiringPiI2CWrite drop \ found valid device if stack = 0
: ?ADS7830 fd_ @ 0 wiringPiI2CWrite 0= if ." ADS7830 found" ELSE ." ADS7830 not found" THEN ;
: readState fd_ @ cmd @ wiringPiI2CWrite drop fd_ @ wiringPiI2CRead adcValue ! ;
: SOFTLIGHT
begin
readState
adcValue @ s>f 255e f/ 3.3e f* voltage f!
ledPin 100e 255e f/ adcValue @ s>f f* f>s softPwmWrite
." ADC value : " adcValue @ 4 u.r ." , Voltage : " voltage f@ 5 2 1 f.rdp ." v" CR
30 delay
key? until
;