Tone functions triggered by digitalRead()

EDIT: Figured out that I’m blind and wasn’t seeing the last two analog inputs on my Pro Mini. But that leads me to my second question, is there a way to make the PWM outputs play nicely together? When multiple notes are played at once through the same speaker with a simple tone command sounds like a complete mess. I’ve seen some youtube videos of the Arduino playing multiple notes at once in a ‘chord,’ but I’ve got absolutely no clue how to do it. The one code example I found was for the Arduino Octosynth http://www.cs.nott.ac.uk/~jqm/wp-content/uploads/2011/11/octosynth-source.txt and that was so absurdly beyond my grasp it’s not even funny.

ORIGINAL POST:
Arduino is my first real introduction to software, though I’ve been building circuits for a while now. I’ve been trying to stumble my way through this for the past four or five hours and keep coming up empty handed. I think what I’m trying to do is simple, but so far no dice.

I’m trying to set up a modified version of the Tone 3 tutorial, but instead of using an analogRead() threshold that is shown in the tutorial I’d like to use digital inputs. My project is using a Pro Mini so I don’t have the five analog inputs that I’d need, which is why I’m looking to the digital pins.

From what I’ve been reading the digital HIGH value happens when the input > 3V, which I can make happen no problem, I just don’t know how to code it.

The Tone 3 sketch is:

#include "pitches.h"

const int threshold = 10;    // minimum reading of the sensors that generates a note

// notes to play, corresponding to the 3 sensors:
int notes[] = {
  NOTE_A4, NOTE_B4,NOTE_C3 };

void setup() {

}

void loop() {
  for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
    // get a sensor reading:
    int sensorReading = analogRead(thisSensor);

    // if the sensor is pressed hard enough:
    if (sensorReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[thisSensor], 20);
    } 
  }
}

I found one example that worked, but it would only play one tone at a time, whichever was attached to a higher physical input number. Though the basic PWM output doesn’t play at all nice when you play more than one note at a time, I’d still like to retain the ability to do so for whenever I can figure out how to play multiple notes together and have them not distort.

My latest attempt at copy/pasting things together is:

#include "pitches.h"
 
 int notes[] = {
  NOTE_A4, NOTE_B4,NOTE_C3 };
  
  
int speaker = 13; // choose the pin for the LED 
int inPin = 7;   // choose the input pin (for a pushbutton) 
int val = 0;     // variable for reading the pin status 
void setup() { 
  pinMode(speaker, OUTPUT);  // declare LED as output 
  pinMode(inPin, INPUT);    // declare pushbutton as input 
} 
void loop(){ 
 for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
    // get a sensor reading:
    int sensorReading = digitalRead(thisSensor);
  if (sensorReading == HIGH) {         // check if the input is HIGH (button released) 
    tone(speaker, notes[thisSensor], 20);
  } }}

I can’t come up with a good way to describe what I’m hearing out of this sketch, besides pulsating noise.

Any help would be greatly appreciated. Also, I’m new around here so not sure the etiquette and didn’t see this listed in the READ THIS FIRST post. For a second question (playing multiple notes together) should I add that into this post, or start a second thread?

What happened to your analog inputs? Aren’t 4 are on the outer row of pins, the other 2 inside of those?

Keep your topic together, don’t go spreading it all over the place.

Oh my gosh... I'm absolutely BLIND!

Yes, yes they are right there... Head-desk

But that leads me to my second question, is there a way to make the PWM outputs play nicely together?

As far as I can see the Tone library uses interrupts to generate tones. I'm not surprised you have trouble with chords.

However the hardware timers can generate 6 PWM outputs simultaneously, if properly configured. I don't know whether or not someone has wrapped that up nicely into an easy-to-use library.