constants [[npix 64]
           [pina $39][button-pin 8]]

to test
dot 0 0 
dot 1 10
dot 2 20
redraw
end

to runcmd
if cmd = 2 [putc button]
end

to colours
setbox1 0 
repeat 10 [all box1 setbox1 box1 + 10 wait 3]
ao
end

to flashes
repeat 10 [all 0 wait 3 ao wait 3]
end

to all :n
let [addr 0]
repeat npix [dot :addr :n make "addr :addr + 1]
redraw
end

define button [][output btstb pina button-pin]	;pa3
define ao [][alloff redraw]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; pins
;;

constants
 [[pinb $23][ddrb $24][portb $25]
  [pind $29][ddrd $2a][portd $2b]
  [didr0 $7e][adcsra $7a][admux $7c][adcl $78][adch $79]
  [tccr0a $44][tccr0b $45][ocr0a $47][ocr0b $48]
  [tccr2a $b0][tccr2b $b1][ocr2b $b4]]

to pin-init
bsetb ddrd $fc		; pins 2-7 as outputs
bsetb portb $0f		; turn on pullups for 8-11
bsetb didr0 $3f
writeb adcsra $86
writeb tccr2a 3		; set up pwm
writeb tccr2b 2
writeb tccr0a 3
writeb tccr0b 2
end

to adread :ch
writeb admux :ch + $40
bsetb adcsra $40
waituntil [not btstb adcsra $40]
output (readb adcl) + (lsh readb adch 8)
end

define a0 [][output adread 0]
define a1 [][output adread 1]
define a2 [][output adread 2]
define a3 [][output adread 3]
define a4 [][output adread 4]
define a5 [][output adread 5]

define sensor0 [][output adread 0]
define sensor1 [][output adread 1]
define sensor2 [][output adread 2]
define sensor3 [][output adread 3]
define sensor4 [][output adread 4]
define sensor5 [][output adread 5]

define in8 [][output btstb pinb 1]
define in9 [][output btstb pinb 2]
define in10 [][output btstb pinb 4]
define in11 [][output btstb pinb 8]

define switch8 [][output not btstb pinb 1]
define switch9 [][output not btstb pinb 2]
define switch10 [][output not btstb pinb 4]
define switch11 [][output not btstb pinb 8]

define on3 [][bsetb portd 8]
define off3 [][bclrb portd 8]
define on4 [][bsetb portd $10]
define off4 [][bclrb portd $10]
define on5 [][bsetb portd $20]
define off5 [][bclrb portd $20]
define on6 [][bsetb portd $40]
define off6 [][bclrb portd $40]
define on7 [][bsetb portd $80]
define off7 [][bclrb portd $80]

define pwm3 [n][bsetb tccr2a $20 writeb ocr2b :n * 255 / 100]
define pwm3off [][bclrb tccr2a $20]
define pwm5 [n][bsetb tccr0a $20 writeb ocr0b :n * 255 / 100]
define pwm5off [][bclrb tccr0a $20]
define pwm6 [n][bsetb tccr0a $80 writeb ocr0a :n * 255 / 100]
define pwm6off [][bclrb tccr0a $80]


