メモリビット比較機能について教えてください。
ここで 4 x HT1632C チップを搭載した LED マトリックスを購入し、Arduino Mega2560で使用しています。
このチップセットで使用できるコードはなく (HT1632 とは異なります)、私は自分で書いています。x、y座標と色を取得し、そのピクセルをオンにするプロット関数があります。これだけで完璧に動作します。
しかし、ディスプレイのパフォーマンスを向上させる必要があるため、デバイス メモリの「コピー」である shadowRam 変数を作成しようとしました。ディスプレイに何かをプロットする前に、shadowRam をチェックして、そのピクセルを変更する必要があるかどうかを確認します。プロット関数でこれ (getShadowRam) を有効にすると、ディスプレイにいくつか (ディスプレイ全体で 3 つまたは 4 つなど) のゴースト ピクセル (オンにする必要のないピクセル) が表示されます。
if
プロット関数でprev_color をコメントするだけで、完全に機能します。
また、すべてのマトリックスをゼロに設定して、shadowRam 配列をクリーニングしています。
変数:
#define BLACK 0
#define GREEN 1
#define RED 2
#define ORANGE 3
#define CHIP_MAX 8
byte shadowRam[63][CHIP_MAX-1] = {0};
getShadowRam
関数:
byte HT1632C::getShadowRam(byte x, byte y) {
byte addr, bitval, nChip;
if (x>=32) {
nChip = 3 + x/16 + (y>7?2:0);
} else {
nChip = 1 + x/16 + (y>7?2:0);
}
bitval = 8>>(y&3);
x = x % 16;
y = y % 8;
addr = (x<<1) + (y>>2);
if ((shadowRam[addr][nChip-1] & bitval) && (shadowRam[addr+32][nChip-1] & bitval)) {
return ORANGE;
} else if (shadowRam[addr][nChip-1] & bitval) {
return GREEN;
} else if (shadowRam[addr+32][nChip-1] & bitval) {
return RED;
} else {
return BLACK;
}
}
プロット機能:
void HT1632C::plot (int x, int y, int color)
{
if (x<0 || x>X_MAX || y<0 || y>Y_MAX)
return;
if (color != BLACK && color != GREEN && color != RED && color != ORANGE)
return;
char addr, bitval;
byte nChip;
byte prev_color = HT1632C::getShadowRam(x,y);
bitval = 8>>(y&3);
if (x>=32) {
nChip = 3 + x/16 + (y>7?2:0);
} else {
nChip = 1 + x/16 + (y>7?2:0);
}
x = x % 16;
y = y % 8;
addr = (x<<1) + (y>>2);
switch(color) {
case BLACK:
if (prev_color != BLACK) { // compare with memory to only set if pixel is other color
// clear the bit in both planes;
shadowRam[addr][nChip-1] &= ~bitval;
HT1632C::sendData(nChip, addr, shadowRam[addr][nChip-1]);
shadowRam[addr+32][nChip-1] &= ~bitval;
HT1632C::sendData(nChip, addr+32, shadowRam[addr+32][nChip-1]);
}
break;
case GREEN:
if (prev_color != GREEN) { // compare with memory to only set if pixel is other color
// set the bit in the green plane and clear the bit in the red plane;
shadowRam[addr][nChip-1] |= bitval;
HT1632C::sendData(nChip, addr, shadowRam[addr][nChip-1]);
shadowRam[addr+32][nChip-1] &= ~bitval;
HT1632C::sendData(nChip, addr+32, shadowRam[addr+32][nChip-1]);
}
break;
case RED:
if (prev_color != RED) { // compare with memory to only set if pixel is other color
// clear the bit in green plane and set the bit in the red plane;
shadowRam[addr][nChip-1] &= ~bitval;
HT1632C::sendData(nChip, addr, shadowRam[addr][nChip-1]);
shadowRam[addr+32][nChip-1] |= bitval;
HT1632C::sendData(nChip, addr+32, shadowRam[addr+32][nChip-1]);
}
break;
case ORANGE:
if (prev_color != ORANGE) { // compare with memory to only set if pixel is other color
// set the bit in both the green and red planes;
shadowRam[addr][nChip-1] |= bitval;
HT1632C::sendData(nChip, addr, shadowRam[addr][nChip-1]);
shadowRam[addr+32][nChip-1] |= bitval;
HT1632C::sendData(nChip, addr+32, shadowRam[addr+32][nChip-1]);
}
break;
}
}
役に立ったら:私が使用しているボードのデータシート。7 ページには、私が使用しているメモリ マッピングがあります。
また、私はディスプレイの動作のビデオを持っています。