Somehow these two don't go together. Could someone explain to me why this is and whether I can work around it?
Somehow they don't go together, huh?
That doesn't convey ANY information to me. Does using both of them together cause compilation errors? Are there common pin usage expectations? What do you mean about them not going together?
When using another input system, for example pressure sensors, I can control the lights using dmx.
When using the Ps2mouse code on itself, I can read the values no problem.
But when I initiate both the mouse and the dmx; it compiles but does not print any values from the mouse.
I stripped the code to see where the problem is and this is what is left. The printing of the x and y values of the mouse stops working if I uncomment the bold line:
#include <ps2.h>
#include <DmxSimple.h>
/*
* an arduino sketch to interface with a ps/2 mouse.
* Also uses serial protocol to talk back to the host
* and report what it finds.
*/
PS2 mouse(2, 3);
void dmx_init(){
DmxSimple.usePin(11);
DmxSimple.maxChannel(8);
}
/*
* initialize the mouse. Reset it, and place it into remote
* mode, so we can get the encoder data on demand.
*/
void mouse_init()
{
mouse.write(0xff); // reset
mouse.read(); // ack byte
mouse.read(); // blank */
mouse.read(); // blank */
mouse.write(0xf0); // remote mode
mouse.read(); // ack
delayMicroseconds(100);
}
void setup()
{
Serial.begin(9600);
[b]//dmx_init();[/b]
mouse_init();
}
/*
* get a reading from the mouse and report it back to the
* host via the serial line.
*/
void loop()
{
char mstat;
char mx;
char my;
/* get a reading from the mouse */
mouse.write(0xeb); // give me data!
mouse.read(); // ignore ack
mstat = mouse.read();
mx = mouse.read();
my = mouse.read();
/* send the data back up */
Serial.print(mstat, BIN);
Serial.print("\tX=");
Serial.print(mx, DEC);
Serial.print("\tY=");
Serial.print(my, DEC);
Serial.println();
}
I added this piece of code to the loop to test it:
if (mx > 20){
dmx_init();
Serial.println("DMX ON!");
}
It printed the values of the mouse until mx was higher than 20 for an instance, it printed the DMX ON!, but then stopped printing the mouse values (and the whole loop).
Disabling the timers when communicating with the mouse in order to make sure the dmx does not interrupt the mouse when sending and receiving data.
Added this to the code:
cli(); // Disabling timers
/* get a reading from the mouse */
mouse.write(0xeb); // give me data!
mouse.read(); // ignore ack
mstat = mouse.read();
mx = mouse.read();
my = mouse.read();
sei(); // Enabling timers