/* int katodaLED[]={22,23,24,25,26,27,28,29};
int anodaLED[]={37,36,35,34,33,32,31,30};
int jeda=10;
void setup() {
// put your setup code here, to run once:
for (int nmr=0;nmr<8;nmr++)
{
pinMode(katodaLED[nmr], OUTPUT);
pinMode(anodaLED[nmr], OUTPUT);
}
}
// Rahmat Wahyuma Akbar
// 22.11.4631
// 22 IF 02
void loop() {
// put your main code here, to run repeatedly:
PORTA=B11111101;PORTC=B00111100;delay(jeda);
PORTA=B11111011;PORTC=B01100110;delay(jeda);
PORTA=B11110111;PORTC=B01100110;delay(jeda);
PORTA=B11101111;PORTC=B00111100;delay(jeda);
PORTA=B11011111;PORTC=B01100110;delay(jeda);
PORTA=B10111111;PORTC=B01100110;delay(jeda);
PORTA=B01111111;PORTC=B00111100;delay(jeda);
}*/
/*byte characters[][8] = {
// 0
{B00111100, B01100110, B01101110, B01110110, B01100110, B01100110, B00111100, B00000000},
// 1
{B00011000, B00111000, B00011000, B00011000, B00011000, B00011000, B01111110, B00000000},
// 2
{B00111100, B01100110, B00000110, B00001100, B00110000, B01100000, B01111110, B00000000},
// 3
{B00111100, B01100110, B00000110, B00011100, B00000110, B01100110, B00111100, B00000000},
// 4
{B00001100, B00011100, B00101100, B01001100, B01111110, B00001100, B00001100, B00000000},
// 5
{B01111110, B01100000, B01111100, B00000110, B00000110, B01100110, B00111100, B00000000},
// 6
{B00111100, B01100000, B01111100, B01100110, B01100110, B01100110, B00111100, B00000000},
// 7
{B01111110, B00000110, B00001100, B00011000, B00110000, B00110000, B00110000, B00000000},
// 8
{B00111100, B01100110, B01100110, B00111100, B01100110, B01100110, B00111100, B00000000},
// 9
{B00111100, B01100110, B01100110, B01100110, B00111110, B00000110, B00111100, B00000000},
// A
{B00111100, B01100110, B01100110, B01111110, B01100110, B01100110, B01100110, B00000000},
// B
{B01111100, B01100110, B01100110, B01111100, B01100110, B01100110, B01111100, B00000000},
// C
{B00111100, B01100110, B01100000, B01100000, B01100000, B01100110, B00111100, B00000000},
// D
{B01111000, B01101100, B01100110, B01100110, B01100110, B01101100, B01111000, B00000000},
// E
{B01111110, B01100000, B01100000, B01111100, B01100000, B01100000, B01111110, B00000000},
// F
{B01111110, B01100000, B01100000, B01111100, B01100000, B01100000, B01100000, B00000000}
};
const int columnPins[] = {22,23,24,25,26,27,28,29};//[for this code connect anode to column][defualt way annode to row]
const int rowPins[] = {37,36,35,34,33,32,31,30};//[for this code connect katode to row][defualt way annode to column]
int currentCharacter = 0; // to select the character to display
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(rowPins[i], OUTPUT);
digitalWrite(rowPins[i], HIGH); // disconnect row pins from Ground
}
for (int i = 0; i < 8; i++) {
pinMode(columnPins[i], OUTPUT);
digitalWrite(columnPins[i], HIGH); // set initial state to LOW for column pins
}
delay(2000);
}
void loop() {
show(characters[1]); // Show current character
delay(2000); // Wait for 2 seconds before switching to the next character
// currentCharacter = (currentCharacter + 1) % 16; // Move to the next character
}
void show(byte* image) {
for (int row = 0; row < 8; row++) {
digitalWrite(rowPins[row], HIGH); // Disconnect column from +5 volts
for (int column = 0; column < 8; column++) {
bool pixel = bitRead(image[column], row); // Read pixel from the image data
digitalWrite(columnPins[column], pixel ? LOW :HIGH ); // Set row LOW if pixel is ON
}
delay(500);
/*delay(5000); // Small delay
for (int row = 0; row < 8; row++) {
digitalWrite(rowPins[row], LOW); // Disconnect row from Ground
}
digitalWrite(columnPins[column], HIGH); // Connect column to Ground
}
}
*/
/*byte characters[][8] = {
{B00111100, B01100110, B01101110, B01110110, B01100110, B01100110, B00111100, B00000000}, // 0
{B00011000, B00111000, B00011000, B00011000, B00011000, B00011000, B01111110, B00000000}, // 1
{B00111100, B01100110, B00000110, B00001100, B00110000, B01100000, B01111110, B00000000}, // 2
// Add bitmaps for 3-9 and A-F here
{B01111110, B00000110, B00000110, B01111100, B00000110, B00000110, B01111100, B00000000}, // F (as an example)
};
const int columnPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
const int rowPins[] = {10, 11, 12, A1, A2, A3, A4, A5};
const int buttonPin = 5; // D5 as pushbutton
int currentCharacter = 0; // to cycle through characters
bool scrollMode = false; // to check if scroll mode is activated
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(rowPins[i], OUTPUT);
pinMode(columnPins[i], OUTPUT);
digitalWrite(columnPins[i], HIGH); // disconnect column pins from Ground
}
pinMode(buttonPin, INPUT_PULLUP); // set the button pin as input
}
void loop() {
if (digitalRead(buttonPin) == LOW) { // Check if button is pressed
scrollMode = !scrollMode; // Toggle scroll mode
delay(200); // Debounce delay
}
if (scrollMode) {
scrollCharacters();
} else {
show(characters[currentCharacter], 1000); // Show current character for 1000 ms
currentCharacter = (currentCharacter + 1) % 16; // Move to next character
}
}
void show(byte* image, unsigned long duration) {
unsigned long start = millis();
while (start + duration > millis()) {
for (int row = 0; row < 8; row++) {
digitalWrite(rowPins[row], HIGH);
for (int column = 0; column < 8; column++) {
bool pixel = bitRead(image[row], column);
digitalWrite(columnPins[column], pixel ? LOW : HIGH); // Set column LOW if pixel is ON
}
delayMicroseconds(300); // Small delay
for (int column = 0; column < 8; column++) {
digitalWrite(columnPins[column], HIGH); // Disconnect column from Gnd
}
digitalWrite(rowPins[row], LOW); // Disconnect row from +5 volts
}
}
}
void scrollCharacters() {
// Implement scrolling characters from left to right
// This function will modify the `show` function to shift the bits of the characters
// and loop through the characters array in a scrolling fashion.
for (int i = 0; i < 8; i++) {
// Shift each character one column to the left
for (int j = 0; j < 8; j++) {
byte shiftedCharacter = characters[currentCharacter][i] << 1;
if (j < 7) {
shiftedCharacter |= bitRead(characters[currentCharacter][i], 7);
}
show(&shiftedCharacter, 100); // Display the shifted character for 100 ms
}
}
}*/
/*byte characters[][8] = {
{B00111100, B01100110, B01101110, B01110110, B01100110, B01100110, B00111100, B00000000}, // 0
{B00011000, B00111000, B00011000, B00011000, B00011000, B00011000, B01111110, B00000000}, // 1
{B00111100, B01100110, B00000110, B00001100, B00110000, B01100000, B01111110, B00000000}, // 2
// Add bitmaps for 3-9 and A-F here
{B01111110, B00000110, B00000110, B01111100, B00000110, B00000110, B01111100, B00000000}, // F (as an example)
};
const int columnPins[] = {37,36,35,34,33,32,31,30};
const int rowPins[] = {22,23,24,25,26,27,28,29};
int currentCharacter = 0; // to select the character to display
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(rowPins[i], OUTPUT);
pinMode(columnPins[i], OUTPUT);
digitalWrite(columnPins[i], HIGH); // disconnect column pins from Ground
}
}
void loop() {
show(characters[currentCharacter]); // Show current character
//delay(2000); // Wait for 2 seconds before switching to the next character
//currentCharacter = (currentCharacter + 1) % 16; // Move to the next character
}
void show(byte* image) {
for (int row = 0; row < 8; row++) {
digitalWrite(rowPins[row], HIGH);
for (int column = 0; column < 8; column++) {
bool pixel = bitRead(image[row], column);
digitalWrite(columnPins[column], pixel ? LOW : HIGH); // Set column LOW if pixel is ON
}
delayMicroseconds(300); // Small delay
for (int column = 0; column < 8; column++) {
digitalWrite(columnPins[column], HIGH); // Disconnect column from Gnd
}
digitalWrite(rowPins[row], LOW); // Disconnect row from +5 volts
}
}*/
/*
* matrixMpxAnimation sketch
* animates two heart images to show a beating heart
*/
// the heart images are stored as bitmaps - each bit corresponds to an LED
// a 0 indicates the LED is off, 1 is on
byte characters[][8] = {
// 0
{B00111100, B01100110, B01101110, B01110110, B01100110, B01100110, B00111100, B00000000},
// 1
{B00011000, B00111000, B00011000, B00011000, B00011000, B00011000, B01111110, B00000000},
// 2
{B00111100, B01100110, B00000110, B00001100, B00110000, B01100000, B01111110, B00000000},
// 3
{B00111100, B01100110, B00000110, B00011100, B00000110, B01100110, B00111100, B00000000},
// 4
{B00001100, B00011100, B00101100, B01001100, B01111110, B00001100, B00001100, B00000000},
// 5
{B01111110, B01100000, B01111100, B00000110, B00000110, B01100110, B00111100, B00000000},
// 6
{B00111100, B01100000, B01111100, B01100110, B01100110, B01100110, B00111100, B00000000},
// 7
{B01111110, B00000110, B00001100, B00011000, B00110000, B00110000, B00110000, B00000000},
// 8
{B00111100, B01100110, B01100110, B00111100, B01100110, B01100110, B00111100, B00000000},
// 9
{B00111100, B01100110, B01100110, B01100110, B00111110, B00000110, B00111100, B00000000},
// A
{B00111100, B01100110, B01100110, B01111110, B01100110, B01100110, B01100110, B00000000},
// B
{B01111100, B01100110, B01100110, B01111100, B01100110, B01100110, B01111100, B00000000},
// C
{B00111100, B01100110, B01100000, B01100000, B01100000, B01100110, B00111100, B00000000},
// D
{B01111000, B01101100, B01100110, B01100110, B01100110, B01101100, B01111000, B00000000},
// E
{B01111110, B01100000, B01100000, B01111100, B01100000, B01100000, B01111110, B00000000},
// F
{B01111110, B01100000, B01100000, B01111100, B01100000, B01100000, B01100000, B00000000}
};
const int columnPins[] = {37,36,35,34,33,32,31,30};
const int rowPins[]= {22,23,24,25,26,27,28,29};
//int katodaLED[]={22,23,24,25,26,27,28,29};
//int anodaLED[]={37,36,35,34,33,32,31,30};
byte temp[8];
void setup() {
for (int i = 0; i < 8; i++)
{
pinMode(rowPins[i], OUTPUT);
pinMode(columnPins[i], OUTPUT);
digitalWrite(columnPins[i], HIGH);
temp[i]=characters[1][i];
}
}
// make all the LED pins outputs
// disconnect column pins from Ground
void loop() {
int pulseDelay = 800 ; // milliseconds to wait between beats
show(temp, 500);
for(int i=0;i<8;i++){
temp[i]=circularShift(temp[i],1,true);
}
delay(100);
}
void show(byte * image, unsigned long duration)
{
unsigned long start = millis();
// begin timing the animation
while (start + duration > millis()) // loop until the duration has passed
{
for(int row = 0; row < 8; row++)
{
digitalWrite(rowPins[row], LOW);
// connect row to +5 volts
for(int column = 0; column < 8; column++)
{
bool pixel = bitRead(image[row],column);
if(pixel == 1)
{
digitalWrite(columnPins[column], HIGH); // connect column to Gnd
}
delayMicroseconds(300);
// a small delay for each LED
digitalWrite(columnPins[column], LOW);
// disconnect column from Gnd
}
digitalWrite(rowPins[row], HIGH);
// disconnect LEDs
}
}
}
// Function to perform circular shift on an 8-bit register
byte circularShift(byte registerValue, int numShifts, bool shiftLeft) {
for (int i = 0; i < numShifts; ++i) {
if (shiftLeft) {
// Shift left
bool shiftedBit = (registerValue >> 7) & 0x01;
registerValue = (registerValue << 1) | shiftedBit;
} else {
// Shift right
bool shiftedBit = registerValue & 0x01;
registerValue = (registerValue >> 1) | (shiftedBit << 7);
}
}
return registerValue;
}