Back in January of 2015, I wanted of use a PING)) ultrasonic sensor to measure distance and send it to the Atari using the 850 - RS232 ports. I initially thought that I could move my hand in front of the sensor and the resulting change in desistance could be used to change the frequency of the sound command. This might have worked if the SIO port could be used to make sound .AND. transmit data to the 850 interface at the same time. It doesn't. So, I forgot about the sound and just got the distance data to the Atari and wrote up the blog entry.
Now that the Arduino Uno to PORTA shield (AU2PORTA) is at my disposal, I can bypass the SIO port and receive the data through the Joystick ports to control the sound frequency. The Arduino reads the sensor data, scales it from 0 to 255, and sets the joystick pins. The Atari simply PEEKs the memory for PORTA and sets the SOUND command.
--------------------------------------------------------
Hardware setup -
- Plug the AU2PORTA shield into the Arduino UNO.
- Connect the PING)) sensor to the Shield.
PING)) ------- Arduino
GND GND
5V 5V
SIG D2
- Plug the AU2PORTA joystick cables into the correct Atari joystick port.
Arduino UNO program -
/* This Arduino program receives data from a PING))sensor.
Then scales the reading to an 8 bit number. That number is
send to the Atari Joystick ports using the AU2PORTA shield.
Pitch data is also sent to the Arduino IDE serial monitor for troubleshooting.
PING))code example used to read sensor (Examples/06.Sensors/Ping)
Kevin Packard January 2019
*/
// Atari PORTA(54016) mapped to pins on arduino
int porta0 = 4;
int porta1 = 5;
int porta2 = 6;
int porta3 = 7;
int porta4 = 8;
int porta5 = 9;
int porta6 = 10;
int porta7 = 11;
int trig1 = 3;
const int pingPin = 2; PING)) //sensor data pin
byte pitch = 0;
byte lastPitch = 0;
byte zero = 0;
void setPorta(byte byteToMap){
// Sets digital pins to transfer data to Atari joystick ports(PORTA)
// When digital port high, joystick pin shorted to ground or logic 0
if (byteToMap & B00000001){digitalWrite(porta0,HIGH);}
else {digitalWrite(porta0,LOW);}
if (byteToMap & B00000010){digitalWrite(porta1,HIGH);}
else {digitalWrite(porta1,LOW);}
if (byteToMap & B00000100){digitalWrite(porta2,HIGH);}
else {digitalWrite(porta2,LOW);}
if (byteToMap & B00001000){digitalWrite(porta3,HIGH);}
else {digitalWrite(porta3,LOW);}
if (byteToMap & B00010000){digitalWrite(porta4,HIGH);}
else {digitalWrite(porta4,LOW);}
if (byteToMap & B00100000){digitalWrite(porta5,HIGH);}
else {digitalWrite(porta5,LOW);}
if (byteToMap & B01000000){digitalWrite(porta6,HIGH);}
else {digitalWrite(porta6,LOW);}
if (byteToMap & B10000000){digitalWrite(porta7,HIGH);}
else {digitalWrite(porta7,LOW);}
}
void setup() {
pinMode(porta0,OUTPUT);
pinMode(porta1,OUTPUT);
pinMode(porta2,OUTPUT);
pinMode(porta3,OUTPUT);
pinMode(porta4,OUTPUT);
pinMode(porta5,OUTPUT);
pinMode(porta6,OUTPUT);
pinMode(porta7,OUTPUT);
pinMode(trig1,OUTPUT);
setPorta(zero);
Serial.begin(9600);//
}
void loop() {
long duration; // from Ping example
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH); //
if(duration < 200 || duration >3500){duration = 200;} // duration 200 us note off
pitch = map(duration,200,3500,0,255); // Scale duration for Atari pitch setting
if(pitch != lastPitch){ // look for pitch change from last setting
digitalWrite(trig1,HIGH); // let atari know not to read pitch while port is being set
setPorta(pitch); // set pins with pitch data
digitalWrite(trig1,LOW); // let atari know data ok to read
lastPitch = pitch; // store latest pitch
Serial.print(pitch); // display pitch in Serial Monitor window(if connected)
Serial.println();
}
delay(100); // delay for PING)) and atari to sync.
}// End of Listing
Atari BASIC code example -
100 IF STRIG(0)=0 THEN 100
200 PITCH=PEEK(54016)
210 IF PITCH=255 THEN VOLUME=0
220 IF PITCH<>255 THEN VOLUME=10
300 IF PITCH=LASTPITCH THEN 100
400 SOUND 0,PITCH,10,VOLUME
500 LASTPITCH=PITCH
510 ? PITCH
600 GOTO 100
While the programs are running, you should be able to move your hand (or other sound reflective object) closer and further from the PING)) sensor to hear a change in pitch.
0 Comments
Recommended Comments
There are no comments to display.