Works fine on an Arduino Uno and Arduino Pro.
As I need some more analog pins I want to switch to an Arduino Mega 2560.
It seems the that are problems regarding the "PORTD" command see below.
Any ideas where to make changes in code for the Arduino Mega?
Thanks!!!
//*********************************************************
// send color values from pixel array to led strip
void show() {
unsigned int ii,b1;
for (ii=0; ii < nled; ii++ ) {
bitWrite(PORTD,datapin,HIGH);
bitWrite(PORTD,clockpin, HIGH);
bitWrite(PORTD,clockpin, LOW);
for ( b1=0x4000; b1; b1 >>= 1) {
if(rgbPixel[ii] & b1) bitWrite(PORTD,datapin, HIGH);
else bitWrite(PORTD,datapin, LOW);
bitWrite(PORTD,clockpin, HIGH);
bitWrite(PORTD,clockpin, LOW);
}
}
latchLeds(nled);
}
//*********************************************************
// activate new color pattern in ledstrip
void latchLeds(int n) {
bitWrite(PORTD,datapin, LOW);
for(int i = 8 * n; i>0; i--) {
bitWrite(PORTD,clockpin, HIGH);
bitWrite(PORTD,clockpin, LOW);
}
}
The point is that a Mega does not have the same port / pin number bit assignment as the smaller Arduinos so you need to either change the code or change the pins you have wired things to.
This thread will explain what is happening:- http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1266009870
No.
You might be able to use PORTE but then you have to change the wiring to reflect the new pins that it maps to.
Direct port mapping like this is processor specific so you need to know how it is wired up to the original port and then see what pin numbers this corresponds to on your Mega, then wire your strip up to those pins.
To write something superfast on pin 2 I should be able by using "bitWrite(PORTE,2,HIGH);" right?
No the bit write is slow as well, you should use:-
PORTE |= 0x80;
Will set bit 7 on PORTE without affecting any of the other bits. Similarly to clear bit 7 use:- PORTE &= ~0x80;
That symbol in front of the 0x80 is a tilde and means the inverse bit pattern of the number.