Hi guys,
I'm trying to display the value of any getdata() on my max7219 controller but everytime that i start the plugin, the 7 segment display goes in confusion displaying just some segment sometimes very bright.
The problem seems to be linked to the Simstart and simscan function. If i remove these function and assign a value to the integer the max7219 work well.Here is my code:
#include <SPI.h>
#include <Ethernet.h>
#include <ARDsim.h>
#include "LedControl.h"
byte MAC[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};// MAC-Address of Arduino
unsigned int XP = 5080; // port to receive Data from Xplane
byte IP[] = {0, 0, 0, 0}; //IP of this Arduino
LedControl lc1=LedControl(12,11,10,1);
void setup()
{
SimStart (XP, MAC, IP);
EncoderPort(5, 8, 9,2,1); // Port:22,23,24; Enc. inputs:36-39;
lc1.shutdown(0,false);
lc1.setIntensity(0,8);
lc1.clearDisplay(0);
EncoderType (2,4,1);
}
void loop()
{
int ones;
int tens;
int hundreds;
SimScan();
int v=GetData(29);
ones=v%10;
v=v/10;
tens=v%10;
v=v/10;
hundreds=v;
lc1.setDigit(0,2,(byte)hundreds,false);
lc1.setDigit(0,1,(byte)tens,false);
lc1.setDigit(0,0,(byte)ones,false);
}
Any help?
Thank you
Hi Fabio,
it's not in the ArdSim, and SimStart and SimScan functions are essential.
If your output dataref #29 is the NAV1 frequency (say 116.05) , you should remember that its value is represented in X-Plane as 11605,
i.e. as 5-digit integer, without decimal point.
So, in your case, if you need only first 3 digits, just devide value by 100:
int v=GetData(29);
v=v/100;
ones=v%10;
v=v/10;
tens=v%10;
v=v/10;
hundreds=v;
--------------------------------
I remember you have written to me on email a week ago (we can continue there)
Regards,
Vlad
Hi Vlad,
i've made a couple of tests and the result is the same.
I've tried with the nav1 sent from x-plane as 11318 and the display goes crazy like the predator clock (remember the movie?). Note that arduino see 116 but this could be a problem of out_1 configuration.
See this video:
https://www.youtube.com/watch?v=jnfuCNcivfU (https://www.youtube.com/watch?v=jnfuCNcivfU)
This video is the max7219 connection test showing everything perfect:
https://www.youtube.com/watch?v=xHVNRIpRQ1M (https://www.youtube.com/watch?v=xHVNRIpRQ1M)
thank you for your patience.
Have a nice day
Fabio,
I can see now where your problem is.
Ethernet shield uses SPI on the pin Arduino #10, and pin #10 should not be used for anything else (as it is noted on the site).
You are using the LedControl library for max7219, this library also uses SPI to communicate with max. (http://playground.arduino.cc/Main/LedControl (http://playground.arduino.cc/Main/LedControl))
As I see in your LedControl setup you set pin #10 for SPI.
LedControl lc1=LedControl(12,11,10,1);
So, there is a conflict between Ethernet shield and max7219, and you get messed values sent to max7219.
Try to choose another pin # for LedControl(12, 11, 9, 1);
And btw, when you take "modulo" for "ones" in your code you shoud do:
ones = v%10; (not ones = v%100;. else you got 2-digit value for "ones")
---------------------------
I will add support of 7-seg LEds in ArdSim library soon (support of 74hc595 registers)
Regards.
Oh Vlad, thank you very much, now it function!
I've completely changed the max7219 pins using 7,8,9 and the displays looks steady and the response is
immediate as i change the value with the encoder.
I continue my project using the max7219; as soon as you implement the new support for the 74hc595, i will decide if migrate on this chip or continue with mine...
Thank you again
Fabio