Multiple inputs and outputs simultaneously

Hello Developers!
I just got my hands on an Arduino Uno and have picked up a project - an electronic drum kit, which utilizes peizoelectric sensors as the drum triggers. I am also using a raspberry pi 3 to detect these signals and make sounds via puredata.

The sensors are hooked up to the arduino, and output pins of the arduino are connected to the raspberry pi. Later, I intend to use analog inputs and send them to puredata via usb midi, but I am just experimenting/testing using digital in and outs for now.

I have no problem using 1 input and output together, i.e. takes an input and and gives output to raspi.

I tried using more inputs and outputs, but could not achieve desirable results... I used more If statements in the "button" example, but nothing.

I am very new to coding. Please help me!
Regards,
Shaurya.

(I would upload the code but I am away from home right now...)

Without showing us your code, how to you expect us to help?

Please read and follow the instructions in the "How to use this forum" post.

The Pi is a 3.3V device to my knowledge; can the inputs handle 5V ?

Or did you take precautions?

Hello! sorry for the inconvenience...
Here is the code. I tried to make some changes to the "button" example in digital examples inside IDE, but I think I did something wrong.

// this constant won't change:
const int pad1 = A0;
const int pad2 = A1;
const int pad3 = A2;
const int pad4 = A3;
const int pad5 = A4;
const int pad6 = A5;
const int pad7 = 0;
const int pad8 = 1;
// outputs

const int outpad1 = 13;
const int outpad2 = 12;
const int outpad3 = 11;
const int outpad4 = 10;
const int outpad5 = 9;
const int outpad6 = 8;
const int outpad7 = 7;
const int outpad8 = 6;

int pad1s = 0;        // current state of the button
int pad2s = 0;
int pad3s = 0;
int pad4s = 0;
int pad5s = 0;
int pad6s = 0;
int pad7s = 0;
int pad8s = 0;

int pad1ls = 0;     // previous state of the button
int pad2ls = 0;
int pad3ls = 0;
int pad4ls = 0;
int pad5ls = 0;
int pad6ls = 0;
int pad7ls = 0;
int pad8ls = 0;

void setup() {
  // initialize the button pin as a input:
  pinMode(pad1, INPUT);
  pinMode(pad2, INPUT);
  pinMode(pad3, INPUT);
  pinMode(pad4, INPUT);
  pinMode(pad5, INPUT);
  pinMode(pad6, INPUT);
  pinMode(pad7, INPUT);
  pinMode(pad8, INPUT);
  
  // initialize the LED as an output:
  pinMode(outpad1, OUTPUT);
  pinMode(outpad2, OUTPUT);
  pinMode(outpad3, OUTPUT);
  pinMode(outpad4, OUTPUT);
  pinMode(outpad5, OUTPUT);
  pinMode(outpad6, OUTPUT);
  pinMode(outpad7, OUTPUT);
  pinMode(outpad8, OUTPUT);}


void loop() {
  // read the pushbutton input pin:
  pad1s = digitalRead(pad1);
  pad2s = digitalRead(pad2);
  pad3s = digitalRead(pad3);
  pad4s = digitalRead(pad4);
  pad5s = digitalRead(pad5);
  pad6s = digitalRead(pad6);
  pad7s = digitalRead(pad7);
  pad8s = digitalRead(pad8);
  
  // compare the buttonState to its previous state
  if (pad1s = pad1ls) {
    // if the state has changed, increment the counter
    if (pad1s == HIGH) {
      digitalWrite(outpad1, HIGH);
    } else {
      // if the current state is LOW then the button went from on to off:
      digitalWrite(outpad1, LOW);
    }
    // Delay a little bit to avoid bouncing
    delay(20);
  }
  // save the current state as the last state, for next time through the loop
  pad1ls = pad1s;

  if (pad2s = pad2ls) {
    // if the state has changed, increment the counter
    if (pad2s == HIGH) {
      digitalWrite(outpad2, HIGH);
    } else {
      // if the current state is LOW then the button went from on to off:
      digitalWrite(outpad2, LOW);
    }
    // Delay a little bit to avoid bouncing
    delay(20);
  }
  // save the current state as the last state, for next time through the loop
  pad2ls = pad2s;

  if (pad3s = pad3ls) {
    // if the state has changed, increment the counter
    if (pad3s == HIGH) {
      digitalWrite(outpad3, HIGH);
    } else {
      // if the current state is LOW then the button went from on to off:
      digitalWrite(outpad3, LOW);
    }
    // Delay a little bit to avoid bouncing
    delay(20);
  }
  // save the current state as the last state, for next time through the loop
  pad3ls = pad3s;

  if (pad4s = pad4ls) {
    // if the state has changed, increment the counter
    if (pad4s == HIGH) {
      digitalWrite(outpad4, HIGH);
    } else {
      // if the current state is LOW then the button went from on to off:
      digitalWrite(outpad4, LOW);
    }
    // Delay a little bit to avoid bouncing
    delay(20);
  }
  // save the current state as the last state, for next time through the loop
  pad4ls = pad4s;

  if (pad5s = pad5ls) {
    // if the state has changed, increment the counter
    if (pad5s == HIGH) {
      digitalWrite(outpad5, HIGH);
    } else {
      // if the current state is LOW then the button went from on to off:
      digitalWrite(outpad5, LOW);
    }
    // Delay a little bit to avoid bouncing
    delay(20);
  }
  // save the current state as the last state, for next time through the loop
  pad5ls = pad5s;

  if (pad6s = pad6ls) {
    // if the state has changed, increment the counter
    if (pad6s == HIGH) {
      digitalWrite(outpad6, HIGH);
    } else {
      // if the current state is LOW then the button went from on to off:
      digitalWrite(outpad6, LOW);
    }
    // Delay a little bit to avoid bouncing
    delay(20);
  }
  // save the current state as the last state, for next time through the loop
  pad6ls = pad6s;

  if (pad7s = pad7ls) {
    // if the state has changed, increment the counter
    if (pad7s == HIGH) {
      digitalWrite(outpad7, HIGH);
    } else {
      // if the current state is LOW then the button went from on to off:
      digitalWrite(outpad7, LOW);
    }
    // Delay a little bit to avoid bouncing
    delay(20);
  }
  // save the current state as the last state, for next time through the loop
  pad7ls = pad7s;

  if (pad8s = pad8ls) {
    // if the state has changed, increment the counter
    if (pad8s == HIGH) {
      digitalWrite(outpad8, HIGH);
    } else {
      // if the current state is LOW then the button went from on to off:
      digitalWrite(outpad8, LOW);
    }
    // Delay a little bit to avoid bouncing
    delay(20);
  }
  // save the current state as the last state, for next time through the loop
  pad8ls = pad8s;
}

please note that the "pads" are the seperate drum triggers.

sterretje:
The Pi is a 3.3V device to my knowledge; can the inputs handle 5V ?

Or did you take precautions?

yes, I did, Thank you!

if (pad1s = pad1ls) {

Change to:

pad1s == pad1ls

etc.

larryd:
if (pad1s = pad1ls) {

Change to:

pad1s == pad1ls

etc.

Thank you for helping me... can You explain to me how this works? Do I still have the IF statement? If not, how does Uno read the status of the digital pins???

Most of your code are repetitions of already written code and therefore you could remove most of the code if you used arrays. So you might want to read up on how to use those.

A = B takes the value from B and puts it into A.

A == B checks to see if A and B have the same value.


Please read these:


if (pad1s = pad1ls) {

Change to:

if (pad1s == pad1ls) {

larryd:
A = B takes the value from B and puts it into A.

A == B checks to see if A and B have the same value.

Thank you very much!!! I understand now...

If you use arrays, your code shrinks dramatically

const byte inputPin[] = { A0, A1, A2, A3, A4, A5, 0, 1 };
const int pinCount = sizeof(inputPin) / sizeof(inputPin[0]);

const byte outputPin[pinCount] = { 13, 12, 11, 10, 9, 8, 7, 6 };  // same number as inputs

byte currentState[pinCount];
byte previousState[pinCount];

void setup() {
  for (int i = 0; i < pinCount; ++i) {
    pinMode(inputPin[i], INPUT);
    pinMode(outputPin[i], OUTPUT);
  }
}


void loop() {
  // read the pushbutton input pin:
  for (int i = 0; i < pinCount; ++i ) {
    currentState[i] = digitalRead(inputPin[i]);
    // compare the buttonState to its previous state
    if (currentState[i] != previousState[i]) {
      // if the state has changed, make output match
      digitalWrite(outputPin[i], currentState[i]);
      // Delay a little bit to avoid bouncing
      delay(20);
    }
    // save the current state as the last state, for next time through the loop
    previousState[i] = currentState[i];

  }
}

Also, how to you have your buttons wired up? You are declaring them as INPUT which means they will need external pull-up or pull-down resistors. Do you have those installed?