Chess board array
Posted: Fri Nov 20, 2015 1:56 am
I am rather new to programming and Python. I have a project I thought I would try to use my pyboard to learn with. It's essentially based off of the work of Bergers who uses a Teensy 2.0 to read a chess board using magnets and reed switches. I have a board (a Mephisto Modular) that works with the Teensy program, so I know the board is good. When I try to use his programming idea - https://sites.google.com/site/bergerspr ... rogramming I run into a problem. The problem is, I always get an entire column turning to 0 instead of just the correct row/column. Below is the code I put together for it so far. I'm sure there are many ways it can be optimized, but again, being new to programming I'm making things work.
What I get when I have a magnet on anything on the A column is:
Any help or ideas why this happens would be appreciated.
Thanks,
Mike
Code: Select all
from pyb import Pin
cletters = ['Y1', 'Y2', 'Y3', 'Y4', 'Y5', 'Y6', 'Y7', 'Y8']
rnumbers = ['X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8']
board = [[0 for j in range(8)] for i in range(8)]
rcount = 0
ccount = 0
for number in rnumbers:
Pin(number, Pin.OUT_PP)
Pin(number).high
for letter in cletters:
Pin(letter, Pin.OUT_PP)
Pin(letter).low
for row in board:
list1 = []
pnum = rnumbers[rcount]
Pin(pnum, Pin.OUT_PP)
Pin(pnum).low
ccount = 0
for e in row:
plet = cletters[ccount]
p_in = Pin(plet, Pin.IN, Pin.PULL_UP)
board[rcount][ccount] = p_in.value()
pvalue = p_in.value()
list1.append(pvalue)
ccount = ccount + 1
rcount = rcount + 1
Pin(pnum).high
print(list1)
print(board)
Code: Select all
>>>
PYB: sync filesystems
PYB: soft reboot
[0, 1, 1, 1, 1, 1, 1, 1]
[0, 1, 1, 1, 1, 1, 1, 1]
[0, 1, 1, 1, 1, 1, 1, 1]
[0, 1, 1, 1, 1, 1, 1, 1]
[0, 1, 1, 1, 1, 1, 1, 1]
[0, 1, 1, 1, 1, 1, 1, 1]
[0, 1, 1, 1, 1, 1, 1, 1]
[0, 1, 1, 1, 1, 1, 1, 1]
[[0, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1]]
MicroPython v1.5-100-g57e00ef on 2015-11-08; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>>
Thanks,
Mike