Need help with QTI Piano — Parallax Forums

# Need help with QTI Piano

Posts: 40
edited 2021-03-03 15:15 in Robotics

I read in the QTI line following tutorial that the QTIs can be used to detect different shades of gray. In my Edison Robotics class, I have the kids drive over a grayscale "piano", and the bot plays different notes depending on which shade it is over.

I had thought that this would be a fun project for the QTIs in my Boe-bot class, but I'm not quite sure how to go about it. Again, I'm not a real programmer/electronics person. Just a mom who was asked to teach a robotics class. The only commands I am familiar with are in Robotics with the Boe-bot and some of What's a Micro. I'm sure there's a better way to accomplish my goal, but I don't know what it is.

Currently the bots are set up for line-following, with 4 qtis plugged into pins 4-7.

This is what I have so far:

'************ Variables ***********************

qtis VAR Nib ' Pins that the QTIs are plugged into
time VAR Nib ' measured RC time
averageTime VAR Word
sum VAR Word ' used to calculate averageTime
PinTime VAR Word ' time stored in each pin
index VAR Nib ' FOR...LOOP counter
sum = 0

DO

DIRB %1111 ' make them outputs
OUTB %1111 ' set them high

PAUSE 0 ' I know need to pause for a time to make sure they are fully charged. Would this be zero????

RCTIME qtis, 1, time ' store the time it took to discharge.

'*********** Average time *********************

FOR index = 4 TO 7
LOOKUP index, time, PinTime
sum = sum + PinTime
Next
averageTime = sum/4 ' How do I store this to one decimal? Do I need to bother with that?
sum = 0 ' reset for next time
'*********** Play Notes ***********************

<<For this I'll need to test what the readings are for the different shades of gray on my piano graphic>>

<< Is there a better way to do this with the index function? Typing 7 if statements seems cumbersome >>

IF (averageTime >= ????) AND (averageTime < ????) THEN ' Whatever grayscale corresponds to C

``` FREQOUT 12, 500, 1046.5                    ' Play a C
```

ELSEIF (average time >= ????) AND (averageTime < ????) THEN ' Whatever grayscale corresponds to D
FREQOUT 12, 500, 1147.7 ' Play a D

etc. for the rest of the notes

LOOP

After we have this done, we could write a program to drive forward/backward over the keyboard and play a song. But I'm not sure how tedious that would be.

Thanks for your help. I tried to find someone else who had done this, but I didn't see anything. If you know of someone who has, then please point me to them. I'd much rather not reinvent the wheel.

Diane