So i have a 1 "master" arduino recieving MIDI signals and then outputing different PWM signals to trigger "slave" arduinos that are connected to a set of relays.
but when i output a PWM signal. the relay lags. it somestimes is really responsive while other times the relay stays on for a few seconds even tho im not pressing a key.
"Master" arduino code
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#define LED 11 // LED pin on Arduino Uno
void setup()
{
pinMode(LED, OUTPUT);
MIDI.begin(); // Launch MIDI, by default listening to channel 1.
Serial.begin(115200);
}
void loop()
{
if (MIDI.read()) // Is there a MIDI message incoming ?
{
switch(MIDI.getType()) // Get the type of the message we caught
{
case midi::NoteOn: // If it is a note on message,
if( MIDI.getData1() == 48) // note off by zero velocity
analogWrite(LED,127);
else if
( MIDI.getData1() == 50) // note off by zero velocity
analogWrite(LED,100);
break;
case midi::NoteOff:
digitalWrite(LED,LOW);
break;
// See the online reference for other message types
default:
break;
}
}
}
Th code of the slave contains Serial.prints… What values do they give You?
Why use rather slow stuff like relays and not things like fast MOSFET transistors?
Robin2:
Why would you use analogWrite() for communication?
Just send the value using Serial or SPI if the distance is very short.
...R
i dunno how. can you post a tutorial link or any reference?
Why use rather slow stuff like relays and not things like fast MOSFET transistors?
[/quote]
when i analogWrite(pin, 127); it returns 10 in the serial monitor.
i am using relays because i am trying to control long lengths of 12v LED Strips. im just using small amounts of led strips to get the coding working and to my standard.
when i analogWrite(pin, 127); it returns 10 in the serial monitor.
50% duty cycle at 490Hz should be around 10 microseconds.
What's the problem?
Edit: whoops - decimal point misplace. Sorry.
Double edit: I missed your divide by 100. Original comment stands.
AWOL:
50% duty cycle at 490Hz should be around 10 microseconds.
What's the problem?
Edit: whoops - decimal point misplace. Sorry.
Double edit: I missed your divide by 100. Original comment stands.
why is it laggy? why does the light act as if the button is sticky?
beensolo:
i dunno how. can you post a tutorial link or any reference?
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable. It's what I use for communication between Arduinos.
You can send data in a compatible format with code like this
A master Arduino to drive slave Arduinos to operate relays is not how it's normally done.
Only beginners might think that's the only way to have more I/O.
One 74HC595 shift register per 8-channel relay board is all you need.
That only uses three Aruino pins from the master, for as many 74HC595/relay boards as you like.
Leo..