Redefinice 2D pole

Wiring, C++, C, Java, ...
Pravidla fóra
Toto subfórum slouží k řešení obecných otázek kolem programování (konstrukce, knihovny, alokace paměti, ...)
hafca
Příspěvky: 86
Registrován: 23 říj 2017, 23:05
Reputation: 0

Redefinice 2D pole

Příspěvek od hafca » 11 črc 2023, 10:37

Pro MAX6921 je v programu 2D pole s rozložením pinů mřížek a segmentů, které mi ale nevyhovuje. Je psaný pro jiný displej a já chci použít IV-18, který je připájená na DPS redukci tak, jak vycházejí piny displeje bez křížení.
Jenže neumím to přečíslovat tak, jak bych potřeboval. Hledal jsem informace o polích, ale stejně z toho nejsem moudrý.
Předpokládám, že je to ta část kódu kterou jsem sem dal. Nahoře je původní rozmístění a dole, jak bych to potřeboval. Nevím od čeho vlastně začít počítat.
Mohla by mi nějaká dobrá duše poradit, jak na to?

Kód: Vybrat vše

/* two dimentional array for holdinPing MAX6921 chip dataPinbyte values
   Grid 1  Grid 2  Grid 3  Grid 4  Grid 5  Grid 6  Grid 7  Grid 8  Grid 9  Grid 10 Grid 11 Grid 12
   OUT11    OUT10    OUT9    OUT8    OUT7    OUT6    OUT5    OUT4    OUT3    OUT2    OUT1   OUT0
PIN  11       12       17     18      19      20      21      22      23      24      25      26
     
   seg. A  seg. B  seg. C  seg. D  seg. E  seg. F  seg. G  seg. DP
   OUT12   OUT13   OUT14   OUT15   OUT16   OUT17   OUT18   OUT19
PIN  10       9       8       7       6       5       4       3
*/

int rows = 0;
int columns = 0;
int clockPin = 25;    // 25,27,29
int loadPin = 27;
int dinPin = 29;
int dataPinRegister[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int offset;

//A F B G E C D,dp
int segmentArray[33][8]={
{ 1,1,1,0,1,1,1,0,  }, //0         
{ 0,0,1,0,0,1,0,0,  }, //1       
{ 1,0,1,1,1,0,1,0,  }, //2     
{ 1,0,1,1,0,1,1,0,  }, //3         
{ 0,1,1,1,0,1,0,0,  }, //4     
{ 1,1,0,1,0,1,1,0,  }, //5       
{ 1,1,0,1,1,1,1,0,  }, //6       
{ 1,0,1,0,0,1,0,0,  }, //7         
{ 1,1,1,1,1,1,1,0,  }, //8         
{ 1,1,1,1,0,1,0,0,  }, //9         
{ 1,1,1,0,1,1,1,1,  }, //0.         
{ 0,0,1,0,0,1,0,1,  }, //1.       
{ 1,0,1,1,1,0,1,1,  }, //2.     
{ 1,0,1,1,0,1,1,1,  }, //3.         
{ 0,1,1,1,0,1,0,1,  }, //4.     
{ 1,1,0,1,0,1,1,1,  }, //5.       
{ 1,1,0,1,1,1,1,1,  }, //6.       
{ 1,0,1,0,0,1,0,1,  }, //7.         
{ 1,1,1,1,1,1,1,1,  }, //8.         
{ 1,1,1,1,0,1,0,1,  }, //9.
{ 0,0,0,1,0,0,0,0,  }, //- G segment / W           
{ 1,1,0,0,1,0,1,0,  }, //C         
{ 1,1,0,1,1,0,0,0,  }, //F           
{ 1,1,1,1,1,0,0,0,  }, //P                           
{ 0,0,0,0,0,0,0,1,  }, //.
{ 1,1,1,1,0,0,0,0,  }, //Upper o           
{ 0,0,1,1,1,0,0,0,  }, // Slash
{ 0,0,0,1,1,1,1,0,  }, //Lower o
{ 0,0,0,0,0,0,0,0,  }, // Blank
{ 0,1,1,1,1,1,0,0,  }, // H
{ 0,0,0,0,0,1,0,0,  }, //- C segment X
{ 0,0,0,0,0,0,1,0,  }, //- D segment  Y
{ 0,0,0,0,1,0,0,0,  }}; //- E segment  Z

// nové rozmístění
/* two dimentional array for holdinPing MAX6921 chip dataPinbyte values

   Grid 1   Grid 2     Grid 3     Grid 4  Grid 5    Grid 6   Grid 7    Grid 8 
   OUT0    OUT1      OUT2      OUT3    OUT4    OUT5    OUT6     OUT7    
PIN  26      25          24          23        22         21        20         19         
     
   seg. A    seg. B    seg. C    seg. D   seg. E   seg. F     seg. G   seg. DP
   OUT12   OUT14   OUT17   OUT18   OUT16   OUT13   OUT15   OUT19
PIN  10        8          5             4          6         9            7          3
*/

Uživatelský avatar
kiRRow
Příspěvky: 1170
Registrován: 07 kvě 2019, 07:03
Reputation: 0
Bydliště: Opava

Re: Redefinice 2D pole

Příspěvek od kiRRow » 11 črc 2023, 17:18

ty piny budou tady dataPinRegister ... To co jsi poslal je mapování čísel a znaků. Pošli to celé ...

hafca
Příspěvky: 86
Registrován: 23 říj 2017, 23:05
Reputation: 0

Re: Redefinice 2D pole

Příspěvek od hafca » 11 črc 2023, 17:46

Hledal jsem to, ale asi špatně. :o

Kód: Vybrat vše

// ILC Clock using 8 ILC VFD displays
// Last Updated: 05-10-19
// Displays Time, Date, Temperature, Humidity, and Pressure, and chimes

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);
#include <IRremote.h>
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini mp3;

#include <SparkFunBME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)

BME280 bme; //Uses I2C address 0x76 (jumper closed)

#include "RTClib.h"
char key_pressed = 0;
int RECV_PIN = A0;
IRrecv irrecv(RECV_PIN);
decode_results results;

RTC_DS3231 rtc;

#define IR_CROSS    0xFFB04F     //     cross

/* two dimentional array for holdinPing MAX6921 chip dataPinbyte values
   Grid 1  Grid 2  Grid 3  Grid 4  Grid 5  Grid 6  Grid 7  Grid 8  Grid 9  Grid 10 Grid 11 Grid 12
   OUT11    OUT10    OUT9    OUT8    OUT7    OUT6    OUT5    OUT4    OUT3    OUT2    OUT1   OUT0
PIN  11       12       17     18      19      20      21      22      23      24      25      26
     
   seg. A  seg. B  seg. C  seg. D  seg. E  seg. F  seg. G  seg. DP
   OUT12   OUT13   OUT14   OUT15   OUT16   OUT17   OUT18   OUT19
PIN  10       9       8       7       6       5       4       3
*/

int rows = 0;
int columns = 0;
int clockPin = 25;    // 25,27,29
int loadPin = 27;
int dinPin = 29;
int dataPinRegister[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int offset;

//A F B G E C D,dp
int segmentArray[33][8]={
{ 1,1,1,0,1,1,1,0,  }, //0         
{ 0,0,1,0,0,1,0,0,  }, //1       
{ 1,0,1,1,1,0,1,0,  }, //2     
{ 1,0,1,1,0,1,1,0,  }, //3         
{ 0,1,1,1,0,1,0,0,  }, //4     
{ 1,1,0,1,0,1,1,0,  }, //5       
{ 1,1,0,1,1,1,1,0,  }, //6       
{ 1,0,1,0,0,1,0,0,  }, //7         
{ 1,1,1,1,1,1,1,0,  }, //8         
{ 1,1,1,1,0,1,0,0,  }, //9         
{ 1,1,1,0,1,1,1,1,  }, //0.         
{ 0,0,1,0,0,1,0,1,  }, //1.       
{ 1,0,1,1,1,0,1,1,  }, //2.     
{ 1,0,1,1,0,1,1,1,  }, //3.         
{ 0,1,1,1,0,1,0,1,  }, //4.     
{ 1,1,0,1,0,1,1,1,  }, //5.       
{ 1,1,0,1,1,1,1,1,  }, //6.       
{ 1,0,1,0,0,1,0,1,  }, //7.         
{ 1,1,1,1,1,1,1,1,  }, //8.         
{ 1,1,1,1,0,1,0,1,  }, //9.
{ 0,0,0,1,0,0,0,0,  }, //- G segment / W           
{ 1,1,0,0,1,0,1,0,  }, //C         
{ 1,1,0,1,1,0,0,0,  }, //F           
{ 1,1,1,1,1,0,0,0,  }, //P                           
{ 0,0,0,0,0,0,0,1,  }, //.
{ 1,1,1,1,0,0,0,0,  }, //Upper o           
{ 0,0,1,1,1,0,0,0,  }, // Slash
{ 0,0,0,1,1,1,1,0,  }, //Lower o
{ 0,0,0,0,0,0,0,0,  }, // Blank
{ 0,1,1,1,1,1,0,0,  }, // H
{ 0,0,0,0,0,1,0,0,  }, //- C segment X
{ 0,0,0,0,0,0,1,0,  }, //- D segment  Y
{ 0,0,0,0,1,0,0,0,  }}; //- E segment  Z


int field_value,test;


//Specify digital pin on the Arduino that the positive lead of piezo buzzer is attached.
int days = 11;
int months = 3;
int years = 19;
int new_days = 11;
int new_months = 3;
int new_years = 19;
int hours = 16;
int minutes = 11;
int seconds = 20;
int new_hours = 16;
int new_minutes = 11;
int new_seconds = 20;
int found, maxIndex;
int digits_entered = 0;
int j,x,y,k,m,n,i,t,a;
int index1;
int chimesVolumn = 20;
int ldrStatus;  // Ambiant light check, less than 600 clock switches off
int ldrLimit = 200;
int sleep_mode = 0;
char testChar,indicator;

String screenSaveRequired;
String chimesRequired = "Y";
String chimesPlayed = "N";
String c_check;
String new_value_1, new_value_2;
String dayString;
String monthString;
String yearString;
String day1,day2;
String month1,month2;
String year1,year2,year3, year4;
String hourString;
String minuteString;
String secondString;
String hour1;
String minute1;
String second1;
String hour2;
String minute2;
String second2,save_second2;
String year_string,date_string;
String timeString, dateString;
String characterArray[7]; // Character Array
String humidityString;
String humidityString1;
String humidityString2;
String pressureString;
String pressureString1;
String pressureString2;
String temperatureCString;
String temperatureCString1;
String temperatureCString2;
String temperatureFString;
String temperatureFString1;
String temperatureFString2;
int pressure,temperatureC, temperatureF, humidity;
DateTime now;

void setup()
{
  // initialize outputs for MAX6921 chip
  pinMode(dinPin, OUTPUT);
  pinMode(loadPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  digitalWrite(clockPin, LOW);
  digitalWrite(loadPin, LOW);
  digitalWrite(dinPin, LOW);
  irrecv.enableIRIn();
  // initialize the lcd
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("ILC Clock v.IR.1");
  rtc.begin(); // Initialize the rtc object
// rtc.adjust(DateTime(2019, 10, 5, 11, 59, 0));
  Wire.begin();
  bme.setI2CAddress(0x76); //Connect to a second sensor 0x76
  if(bme.beginI2C() == false)
  {
    Serial.println("Sensor B connect failed");
  }
  indicator = 'W'; // first part of rolling time seperator
  sleep_mode = 0;
  screenSaveRequired = "Y";
  chimesPlayed = "N";
  // setup chimes
  mySoftwareSerial.begin(9600);
  mp3.begin(mySoftwareSerial);
  mp3.reset();
  mp3.volume(30);  //Set volume value. From 0 to 30
}   

void loop()
{
  // Check that light levels are OK, if dark then switch off Nixie tubes until
  // light levels return to full.                 
  light_detection();
  if (sleep_mode != 1) {
    DateTime now = rtc.now();
    // Display time for 30 seconds
    display_time();
    lcd_display();
     // equates to a display time of 40 seconds  = 4200
    for (t = 1; t <= 100; t++)
    {   
      check_user_input();
      // Display time on VFD screen
      display_time();
      // Check for Chime
      if (chimesRequired == "Y" && chimesPlayed == "N") {
        c_check = characterArray[3] + characterArray[4];
        if (c_check == "00" || c_check == "15" || c_check == "30" || c_check == "45") {
          play_chimes();                 
          chimesPlayed = "Y";
        }
      }   
    }
    chimesPlayed = "N";
    // Display date   
    dayString = now.day();
    // Display date on VFD screen
    display_date();
    lcd_display();
     // equates to a display time of 5 seconds = 400
    for (t = 1; t <= 50; t++)
    {         
      check_user_input();
      // Display date on VFD screen
      display_date();
    }
    // Display temperature in Celisus
    temperatureC = bme.readTempC();   
    // Display temperatureC on VFD screen
    display_temperatureC();
    lcd_display();
    for (t = 1; t <= 50; t++)
    {     
      check_user_input();
      // Display temperatureC on VFD screen
      display_temperatureC();         
    }
    
    
    // Display pressure in mB
   pressure = bme.readFloatPressure()/100.0F + 46;
    // Display pressure on VFD screen
    display_pressure();
   lcd_display();   
    for (t = 1; t <= 50; t++)
    {
    
      check_user_input();
      // Display pressure on VFD screen                 
      display_pressure();
    }
    // Display humidity
    humidity = bme.readFloatHumidity();
    // Display humidity on VFD screen       
    display_humidity();
    lcd_display();
    for (t = 1; t <= 50; t++)
    {       
      check_user_input();
      // Display humidity on VFD screen         
      display_humidity();
    }
  }       
}

void light_detection()
{
  ldrStatus = analogRead(A15);
  // Adjustment for difference between this clock and the original clock
  // this will ensure that both clocks switch off approximately at the same time.
  ldrStatus = ldrStatus * 100; 
  sleep_mode = 0;
  if (ldrStatus <= ldrLimit && screenSaveRequired == "Y") {
    sleep_mode = 1;
    // Setup Blank Screen
    characterArray[0] = " ";
    characterArray[1] = " ";
    characterArray[2] = " ";
    characterArray[3] = " ";
    characterArray[4] = " ";
    characterArray[5] = " ";   
    characterArray[6] = " ";
    characterArray[7] = " ";
    lcd.setCursor(0,1);
    lcd.print(" SLEEP MODE     ");
    process_display();
  }
}

// Funkce pro nacteni a prevod kodu z IR ovladace na znaky '0' az '9' a '#'
char convert_key ()
{
  char Ret = 0;
  results.value = 0;
  // nacteni kodu z IR ovladace
  if (irrecv.decode(&results)) {
    // uspesne nacteno, prikazem resume povolime dalsi cteni do budocuna
    irrecv.resume();
  } else {
    // nenacteno
    results.value = 0;
  }
  delay(100);
  switch (results.value) {
    case 0xFF9867:
      // predpokladam, ze toto ma byt znak char '0' tj. hodnota dekadicky 48
      Ret = 48;
      break;
    case 0xFFA25D:
      // predpokladam, ze toto ma byt znak char '1' tj. hodnota dekadicky 49
      Ret = 49;
      break;
    case 0xFF629D:
      // predpokladam, ze toto ma byt znak char '2' tj. hodnota dekadicky 50
      Ret = 50;
      break;
    case 0xFFE21D:
      // predpokladam, ze toto ma byt znak char '3' tj. hodnota dekadicky 51
      Ret = 51;
      break;
    case 0xFF22DD:
      // predpokladam, ze toto ma byt znak char '4' tj. hodnota dekadicky 52
      Ret = 52;
      break;
    case 0xFF02FD:
      // predpokladam, ze toto ma byt znak char '5' tj. hodnota dekadicky 53
      Ret = 53;
      break;
    case 0xFFC23D:
      // predpokladam, ze toto ma byt znak char '6' tj. hodnota dekadicky 54
      Ret = 54;
      break;
    case 0xFFE01F:
      // predpokladam, ze toto ma byt znak char '7' tj. hodnota dekadicky 55
      Ret = 55;
      break;
    case 0xFFA857:
      // predpokladam, ze toto ma byt znak char '8' tj. hodnota dekadicky 56
      Ret = 56;
      break;
    case 0xFF906F:
      // predpokladam, ze toto ma byt znak char '9' tj. hodnota dekadicky 57
      Ret = 57;
      break;
    case 0xFFB04F:
      // predpokladam, ze toto ma byt znak char '#' tj. hodnota dekadicky 35
      Ret = 35;
      break;
    default:
      // nepodporovany znak tj. vrací se hodnota 0
      Ret = 0;
      break;
  }
  return Ret;
}

void process_chime_display()
{
  // Chime Screen
  characterArray[0] = " ";
  characterArray[1] = " ";
  characterArray[2] = " ";
  characterArray[3] = " ";
  characterArray[4] = " ";
  characterArray[5] = " ";   
  characterArray[6] = " ";
  characterArray[7] = ".";
  process_display();
}

void play_chimes()
{
  if (c_check == "00") {         
    // Sound hourly chime
    c_check = characterArray[0] + characterArray[1];
    process_chime_display();
    mp3.play(16);
    delay(19000);
    if (c_check == "01" || c_check == "13") {
      // Play 1 Hour Chime
      mp3.play(1);
      delay(3000);           
    }
    if (c_check == "02" || c_check == "14") {
      // Play 2 Hour Chime
      mp3.play(2);
      delay(5000);           
    }
    if (c_check == "03" || c_check == "15") {         
      // Play 3 Hour Chime
      mp3.play(3);
      delay(7000);                 
    }
    if (c_check == "04" || c_check == "16") {       
      // Play 4 Hour Chime
      mp3.play(4);
      delay(9000);                   
    }
    if (c_check == "05" || c_check == "17") {         
      // Play 5 Hour Chime
      mp3.play(5);
      delay(11000);               
    }
    if (c_check == "06" || c_check == "18") {         
      // Play 6 Hour Chime
      mp3.play(6);
      delay(13000);                     
    }
    if (c_check == "07" || c_check == "19") {         
      // Play 7 Hour Chime
      mp3.play(7);         
      delay(15000);   
    }
    if (c_check == "08" || c_check == "20") {     
      // Play 8 Hour Chime
      mp3.play(8);   
      delay(17000);               
    }
    if (c_check == "09" || c_check == "21") {       
      // Play 9 Hour Chime
      mp3.play(9);         
      delay(19000);
    }
    if (c_check == "10" || c_check == "22") {       
      // Play 10 Hour Chime
      mp3.play(10);       
      delay(21000);
    }
    if (c_check == "11" || c_check == "23") {         
      // Play 11 Hour Chime
      mp3.play(11);
      delay(23000);       
    }
    if (c_check == "12" || c_check == "00") {       
      // Play 12 Hour Chime
      mp3.play(12);
      delay(25000);       
    }                   
  } else {
    process_chime_display();   
    if (c_check == "15") {
      // play 15 Minute chime
      mp3.play(13);         
    }
    if (c_check == "30") {
      // play 30 Minute chime           
      mp3.play(14);   
    }
    if (c_check == "45") {             
      // play 45 Minute chime
      mp3.play(15);   
    }
  }     
}

void check_user_input()
{
  key_pressed = convert_key();
  if (key_pressed != 0) {
    if (key_pressed == '#') {
      adjustValues();
    }
  }
}

// Display on the LCD exactly what is stored in the character array.
void lcd_display()
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("ILC Clock IR 1.0");
  lcd.setCursor(1,1);
  lcd.print(characterArray[0]);
  lcd.print(characterArray[1]);
  if (characterArray[2] == "W" || characterArray[2] == "X" ||
      characterArray[2] == "Y" || characterArray[2] == "Z") {
    lcd.print(".");
  } else {
    lcd.print(characterArray[2]);
  }
  lcd.print(characterArray[3]);
  lcd.print(characterArray[4]);
  if (characterArray[2] == "W" || characterArray[2] == "X" ||
      characterArray[2] == "Y" || characterArray[2] == "Z") {
    lcd.print(".");
  } else {
    lcd.print(characterArray[5]);
  }
  lcd.print(characterArray[6]);
  lcd.print(characterArray[7]);
}

void display_time()
{
  now = rtc.now();
  hourString = now.hour();
  test = hourString.length();
  if (test == 1) {
    hour1 = " ";
    hour2 = hourString.substring(0,1);       
  } else {
    hour1 = hourString.substring(0,1);
    hour2 = hourString.substring(1,2);
  }
  minuteString = now.minute();
  test = minuteString.length();
  if (test == 1) {
    minute1 = "0";
    minute2 = minuteString.substring(0,1);       
  } else {
    minute1 = minuteString.substring(0,1);
    minute2 = minuteString.substring(1,2);
  }
  secondString = now.second();
  test = secondString.length();
  if (test == 1) {
    second1 = "0";
    second2 = secondString.substring(0,1);       
  } else {
    second1 = secondString.substring(0,1);
    second2 = secondString.substring(1,2);
  }
  characterArray[0] = hour1;
  characterArray[1] = hour2;
  characterArray[2] = indicator;
  characterArray[3] = minute1;
  characterArray[4] = minute2;
  characterArray[5] = indicator;   
  characterArray[6] = second1;
  characterArray[7] = second2;
  if (second2 != save_second2) {
    // Move the indicator one position at the change of each second
    if (indicator == 'W') {
      indicator = 'X';
    } else if (indicator == 'X') {
      indicator = 'Y';
    } else if (indicator == 'Y') {
      indicator = 'Z';
    } else {
      indicator = 'W';
    }
    save_second2 = second2;                     
  }
  // Test Array     
  //  characterArray[0] = "0";
  //  characterArray[1] = "1";
  //  characterArray[2] = "2";
  //  characterArray[3] = "3";
  //  characterArray[4] = "4";
  //  characterArray[5] = "5";   
  //  characterArray[6] = "6";
  //  characterArray[7] = "7";
  process_display();       
}

void display_date()
{
  now = rtc.now();
  dayString = now.day();
  test = dayString.length();
  if (test == 1) {
    day1 = " ";
    day2 = dayString.substring(0,1);       
  } else {
    day1 = dayString.substring(0,1);
    day2 = dayString.substring(1,2);
  }
  monthString = now.month();
  test = monthString.length();
  if (test == 1) {
    month1 = "0";
    month2 = monthString.substring(0,1);       
  } else {
    month1 = monthString.substring(0,1);
    month2 = monthString.substring(1,2);
  }
  yearString = now.year();
  year1 = yearString.substring(0,1);
  year2 = yearString.substring(1,2);
  year3 = yearString.substring(2,3);
  year4 = yearString.substring(3,4);
  characterArray[0] = day1;
  characterArray[1] = day2;
  characterArray[2] = "-";
  characterArray[3] = month1;
  characterArray[4] = month2;
  characterArray[5] = "-";
  characterArray[6] = year3;
  characterArray[7] = year4;
  process_display();
}

void display_temperatureC()
{
  temperatureCString = String(temperatureC);
  temperatureCString1 = getValue(temperatureCString, ' ', 0); // 99.
  temperatureCString2 = getValue(temperatureCString, ' ', 1); // .99
  characterArray[0] = " ";   
  characterArray[1] = temperatureCString1.substring(0,1);
  characterArray[2] = temperatureCString1.substring(1,2);
  characterArray[3] = " ";
  characterArray[4] = temperatureCString2.substring(0,1);
  characterArray[5] = temperatureCString2.substring(1,2);
  characterArray[6] = "";
  characterArray[7] = "C";
  process_display();
}


void display_pressure()
{
  pressureString = String(pressure);
  pressureString1 = getValue(pressureString, ' ', 0); // 9999.
  pressureString2 = getValue(pressureString, ' ', 1); // .99
  if (pressureString1.substring(0,1) == "9") {
    // correctly display pressure values less than 1000 mB
    characterArray[0] = " ";
    characterArray[1] = pressureString1.substring(0,1);
    characterArray[2] = pressureString1.substring(1,2);
    characterArray[3] = pressureString1.substring(2,3);
  } else {
    characterArray[0] = pressureString1.substring(0,1);
    characterArray[1] = pressureString1.substring(1,2);
    characterArray[2] = pressureString1.substring(2,3);
    characterArray[3] = pressureString1.substring(3,4);
  }
  characterArray[4] = " ";
  characterArray[5] = pressureString2.substring(0,1);
  characterArray[6] = pressureString2.substring(1,2);
  characterArray[7] = "P";   
  process_display();
  
}

void display_humidity()
{
  humidityString = String(humidity);
  humidityString1 = getValue(humidityString, ' ', 0); // 99.
  humidityString2 = getValue(humidityString, ' ', 1); // .99
  characterArray[0] = humidityString2.substring(0,1);
  characterArray[1] = humidityString2.substring(1,2);
  characterArray[2] = " ";
  characterArray[3] = humidityString1.substring(0,1);
  characterArray[4] = humidityString1.substring(1,2);
  characterArray[5] = " o";
  characterArray[6] = "/";
  characterArray[7] = "o";
  process_display();
}

void adjustValues()
{
  now = rtc.now();

  // get current time and date, populate adjustment fields.
  hourString = now.hour();
  minuteString = now.minute();
  secondString = now.second();
  hour1 = hourString.substring(0,2);
  minute1 = minuteString.substring(0,2);
  second1 = secondString.substring(0,2);
             
  dayString = now.day();
  monthString = now.month();
  yearString = now.year();
  day1 = dayString.substring(0,2);
  month1 = monthString.substring(0,2);
  year1 = yearString.substring(2,4);           
   
  new_days = day1.toInt();
  new_months = month1.toInt();
  new_years = year1.toInt();
 
  new_hours = hour1.toInt();
  new_minutes = minute1.toInt();
  new_seconds = second1.toInt();
   
  lcd.clear();
  lcd.setCursor(0,0);           
  lcd.print("Clock Adjustment");
         
  delay(700);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("   Days(DD): ");
  lcd.print(new_days);
  adjust_field(1);
  delay(200);
         
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" Months(MM): ");
  lcd.print(new_months);
  adjust_field(2);
  delay(200);
                 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("  Years(YY): ");
  lcd.print(new_years);
  adjust_field(3);
  delay(200);
 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("  Hours(HH): ");
  lcd.print(new_hours);
  adjust_field(4);
  delay(200);
         
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Minutes(MM): ");
  lcd.print(new_minutes);
  adjust_field(5);
  delay(200);   
               
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Seconds(SS): ");
  lcd.print(new_seconds);
  adjust_field(6);
  delay(200);   
 
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("Set:1=Y/0=N  ");
  lcd.setCursor(0,0);
  lcd.print("Chimes:      ");
  lcd.print(chimesRequired);
  adjust_field(7);
  delay(200);   
 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Volume(VV):  ");
  lcd.print(chimesVolumn);
  adjust_field(8);
  delay(200);                     
 
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("Set:1=Y/0=N  ");
  lcd.setCursor(0,0);
  lcd.print("Screen Save: ");
  lcd.print(screenSaveRequired);
  adjust_field(9);
  delay(200);
         
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" New Values Set");
  mp3.volume(chimesVolumn);  //Set volume value. From 0 to 30
  new_years = 2000 + new_years;   
  rtc.adjust(DateTime(new_years, new_months, new_days, new_hours, new_minutes, new_seconds));     
}

void adjust_field(int field)

{
  field_value = field;
  digits_entered = 13;
  key_pressed = convert_key();
  while (key_pressed != '#')
  {
    if (key_pressed == '0' || key_pressed == '1' || key_pressed == '2' ||
        key_pressed == '3' || key_pressed == '4' || key_pressed == '5' ||
        key_pressed == '6' || key_pressed == '7' || key_pressed == '8' ||
        key_pressed == '9') {
      if (digits_entered == 13) {
        lcd.setCursor(digits_entered,0);
        digits_entered = digits_entered + 1;
        lcd.print(key_pressed);
      } else {
        if (digits_entered == 14) {
          lcd.setCursor(digits_entered,0);
          digits_entered = digits_entered + 1;       
          lcd.print(key_pressed);
        } else {
          display_Error(2);
          digits_entered = 13;
        }
      }                       
      switch (field_value) {
        case 1:
          if (digits_entered == 14) {
            new_days = (int)key_pressed - 48;
          } else {
            new_days = (new_days * 10) + (int)key_pressed - 48;   
          }         
          break;
        case 2:
          if (digits_entered == 14) {
            new_months = (int)key_pressed - 48;
          } else {
            new_months = (new_months * 10) + (int)key_pressed - 48;   
          }
          break;
        case 3:
          if (digits_entered == 14) {
            new_years = (int)key_pressed - 48;
          } else {
            new_years = (new_years * 10) + (int)key_pressed - 48;   
          }       
          break;         
        case 4:
          if (digits_entered == 14) {
            new_hours = (int)key_pressed - 48;
          } else {
            new_hours = (new_hours * 10) + (int)key_pressed - 48;   
          }
          break;
        case 5:
          if (digits_entered == 14) {
            new_minutes = (int)key_pressed - 48;
          } else {
            new_minutes = (new_minutes * 10) + (int)key_pressed - 48;   
          }
          break;
        case 6:
          if (digits_entered == 14) {
            new_seconds = (int)key_pressed - 48;
          } else {
            new_seconds = (new_seconds * 10) + (int)key_pressed - 48;   
          }               
          break;
        case 7:
          if ((int)key_pressed - 48 == 1) {
            chimesRequired = "Y";
          } else {
            chimesRequired = "N";                   
          }             
          break;
        case 8:
          if (digits_entered == 14) {
            chimesVolumn = (int)key_pressed - 48;
          } else {
            chimesVolumn = (chimesVolumn * 10) + (int)key_pressed - 48;   
          }   
          break;                   
        case 9:
          if ((int)key_pressed - 48 == 1) {
            screenSaveRequired = "Y";
          } else {
            screenSaveRequired = "N";                   
          }             
          break;
      }
    }
    key_pressed = 0;
    // Wait for user to press a key on the keypad
    while (key_pressed == 0)
    {
      key_pressed = convert_key();
      delay(100);
    }
  }
}

void display_Error(int type)
{
  lcd.setCursor(0,1);
  if (type == 1 ) {
    lcd.print("  Invalid Entry ");   
  } else {
    lcd.print("Too many digits ");   
  }
  delay (200);
  lcd.setCursor(0,1);
  lcd.print("                ");     
  lcd.setCursor(0,0);
  if (field_value == 1) {
    lcd.print("   Days(DD): ");   
    new_days = day1.toInt();
    lcd.print(new_days);         
  }
  if (field_value == 2) {
    lcd.setCursor(0,0);
    lcd.print("                ");
    lcd.setCursor(0,0);   
    lcd.print(" Months(MM): ");   
    new_months = month1.toInt();
    lcd.print(new_months);         
  }
  if (field_value == 3) {
    lcd.print("  Years(YY): ");   
    new_years = year1.toInt();
    lcd.print(new_years);         
  }
  if (field_value == 4) {
    lcd.print("  Hours(HH): ");
    new_hours = hour1.toInt();
    lcd.print(new_hours);         
  }     
  if (field_value == 5) {
    lcd.print("Minutes(MM): ");
    new_minutes = minute1.toInt();
    lcd.print(new_minutes);         
  }     
  if (field_value == 6) {
    lcd.print("Seconds(SS): ");
    new_seconds = second1.toInt();
    lcd.print(new_seconds);         
  }     
  if (field_value == 8) {
    lcd.print("Volume(VV):  ");
    lcd.print(chimesVolumn);     
  }   
}

String getValue(String dataPin, char separator, int index2)
{
  found = 0;
  int strIndex[] = { 0, -1 };
  maxIndex = dataPin.length() - 1;
  for (i = 0; i <= maxIndex && found <= index2; i++)
  {
    if (dataPin.charAt(i) == separator || i == maxIndex) {
      found++;
      strIndex[0] = strIndex[1] + 1;
      strIndex[1] = (i == maxIndex) ? i+1 : i;
    }
  }
  return found > index2 ? dataPin.substring(strIndex[0], strIndex[1]) : "";
}

void write_loadPin()
{
  digitalWrite(loadPin, HIGH);
  digitalWrite(loadPin, LOW);
}

void write_clockPin()
{
  digitalWrite(clockPin, HIGH);
  digitalWrite(clockPin, LOW);
}

void write_character()
{
  if (characterArray[7-offset] == "0") index1 = 0;
  if (characterArray[7-offset] == "1") index1 = 1;
  if (characterArray[7-offset] == "2") index1 = 2;
  if (characterArray[7-offset] == "3") index1 = 3;
  if (characterArray[7-offset] == "4") index1 = 4;
  if (characterArray[7-offset] == "5") index1 = 5;
  if (characterArray[7-offset] == "6") index1 = 6;                       
  if (characterArray[7-offset] == "7") index1 = 7;
  if (characterArray[7-offset] == "8") index1 = 8;
  if (characterArray[7-offset] == "9") index1 = 9;
  if (characterArray[7-offset] == "0.") index1 = 10;
  if (characterArray[7-offset] == "1.") index1 = 11;
  if (characterArray[7-offset] == "2.") index1 = 12;
  if (characterArray[7-offset] == "3.") index1 = 13;
  if (characterArray[7-offset] == "4.") index1 = 14;
  if (characterArray[7-offset] == "5.") index1 = 15;
  if (characterArray[7-offset] == "6.") index1 = 16;                       
  if (characterArray[7-offset] == "7.") index1 = 17;
  if (characterArray[7-offset] == "8.") index1 = 18;
  if (characterArray[7-offset] == "9.") index1 = 19;     
  if (characterArray[7-offset] == "-") index1 = 20;
  if (characterArray[7-offset] == "C") index1 = 21;
  if (characterArray[7-offset] == "F") index1 = 22;
  if (characterArray[7-offset] == "P") index1 = 23;
  if (characterArray[7-offset] == ".") index1 = 24;
  if (characterArray[7-offset] == "O") index1 = 25;                       
  if (characterArray[7-offset] == "/") index1 = 26;
  if (characterArray[7-offset] == "o") index1 = 27;
  if (characterArray[7-offset] == " ") index1 = 28;
  if (characterArray[7-offset] == "H") index1 = 29;                 
  if (characterArray[7-offset] == "W") index1 = 20;
  if (characterArray[7-offset] == "X") index1 = 30;
  if (characterArray[7-offset] == "Y") index1 = 31;
  if (characterArray[7-offset] == "Z") index1 = 32;
}

void process_display()
{
  for (offset = 7; offset >= 0; offset--)  // was 9
  {
    write_character();
    write_clockPin();     
    for (i = 19; i >= 0; i--)
    {
      if (i >= 12) {
        dataPinRegister[i] = segmentArray[index1][i-12];
      }
      digitalWrite(dinPin, dataPinRegister[i]);         
      write_clockPin();
    }
    write_loadPin();
    dataPinRegister[offset] = 0;
    if (offset != 0) {
      dataPinRegister[offset-1] = 1;
    } else {
      dataPinRegister[7] = 1; // was 9
    }
    delay(1);   
  }
} 

Uživatelský avatar
kiRRow
Příspěvky: 1170
Registrován: 07 kvě 2019, 07:03
Reputation: 0
Bydliště: Opava

Re: Redefinice 2D pole

Příspěvek od kiRRow » 12 črc 2023, 17:43

Tak jsi měl asi částečně pravdu ... ono to tam nějak do toho dvourozměrného pole je zakódováno a dekóduje se to dle mého názoru tady

Kód: Vybrat vše

void process_display()
{
  for (offset = 7; offset >= 0; offset--)  // was 9
  {
    write_character();
    write_clockPin();     
    for (i = 19; i >= 0; i--)
    {
      if (i >= 12) {
        dataPinRegister[i] = segmentArray[index1][i-12];
      }
      digitalWrite(dinPin, dataPinRegister[i]);         
      write_clockPin();
    }
    write_loadPin();
    dataPinRegister[offset] = 0;
    if (offset != 0) {
      dataPinRegister[offset-1] = 1;
    } else {
      dataPinRegister[7] = 1; // was 9
    }
    delay(1);   
  }
} 
omlouvám se ale, momentálně jsem po docela dlouhý šichtě a už nad tím neumím přemýšlet ... nějaký odkaz na orginál odkud to je vzaté ? ... třeba se tam člověk dočte co tím chtěl pan programátor říct ... čím více infa, tím větší šance, že to někdo rozlouskne

hafca
Příspěvky: 86
Registrován: 23 říj 2017, 23:05
Reputation: 0

Re: Redefinice 2D pole

Příspěvek od hafca » 12 črc 2023, 18:05

Já to tam studoval mockrát, ale nic co by mi pomohlo jsem tam nenašel.
Odkaz je tady https://www.instructables.com/ILC1-18L-Clock/, ale nelámej to přes koleno. Chtěl jsem využít ten displej a tohle se mi zdálo docela fajn. On tam sice má veliká čísla, ale jinak než tím displejem se to podle mě neliší, 8 míst je na obou.

AstroMiK
Příspěvky: 593
Registrován: 08 pro 2017, 19:05
Reputation: 0

Re: Redefinice 2D pole

Příspěvek od AstroMiK » 17 črc 2023, 13:20

kiRRow má pravdu, že je to v tom podprogramu 'process_display()'.

Podle mě by bylo nejjednodušší, kdyby se zavedlo pole, které by obsahovalo nově namapované výstupy ('premapovani[]').
Pak by se neodesílaly okamžitě jednotlivé bity na výstupní pin, ale nejdřív by se připravilo pole pro odeslání 'dataPinRegister[]' (připravovalo by se na přeskáčku podle toho, jak by jednotlivé prvky byly napamapované).

A na závěr, když by bylo to pole připravené, tak by se v jedné smyčce celé odeslalo na výstup.

Zkusil jsem to tady načrtnout i s komentáři, ale nemám to jak vyzkoušet.
To pole 'premapovani[]' si musíš nastavit tak, jak to potřebuješ. Sice na začátku programu v komentáři uvádíš ty nové PINy, ale je nutné tam zadávat čísla OUTů podle katalogového listu tvého konkrétního budiče.

Kód: Vybrat vše

void process_display()
  {
  
   byte premapovani[20];

   //     stary OUT           novy OUT         puvodni funkce
   premapovani[0]         =       0;            // grid
   premapovani[1]         =       1;            // grid
   premapovani[2]         =       2;            // grid
   premapovani[3]         =       3;            // grid
   premapovani[4]         =       4;            // grid
   premapovani[5]         =       5;            // grid
   premapovani[6]         =       6;            // grid
   premapovani[7]         =       7;            // nepouzito
   premapovani[8]         =       8;            // nepouzito
   premapovani[9]         =       9;            // nepouzito
   premapovani[10]        =      10;            // nepouzito
   premapovani[11]        =      11;            // nepouzito
   premapovani[12]         =     12;            // segment
   premapovani[13]         =     13;            // segment
   premapovani[14]         =     14;            // segment
   premapovani[15]         =     15;            // segment
   premapovani[16]         =     16;            // segment
   premapovani[17]         =     17;            // segment
   premapovani[18]         =     18;            // segment
   premapovani[19]         =     19;            // segment
  

    for (offset = 7; offset >= 0; offset--)                            //   8 zobrazovacich jednotek
      {

        for (int zhasinani = 19 ; zhasinani >= 0 ; zhasinani --)       // vsech 8 gridu a 8 segmentu se pripravi na zhasnuti
          {
            dataPinRegister[premapovani[zhasinani]] = 0;               // zatim se s vystupem nic nedeje, jen se pripravuje odesilaci pole
          }
        dataPinRegister[premapovani[offset]] = 1;                      // aktualni grid se pripravi na rozsviceni


        write_character();                                             // vrati 'index1' nejake definice znaku, ktera odpovida vstupnimu textu

      
        for (int i = 19; i >= 12; i--)                                 // podobne se jen pripravi segmenty (puvodne byly na pozicich 12 az 19)
          {
            dataPinRegister[premapovani[i]] = segmentArray[index1][premapovani[i-12]];     // zatim se s vystupem nic nedeje, jen se pripravuje odesilaci pole
          }


        // ---- tady je pole 'dataPinRegister[]' uz kompletne pripravene a zacne se presypavat bit po bitu na vystup -----

        write_clockPin();                                              // HIGH impulz na CLK

        for (int i = 19; i>=0 ; i--)                                   // cele pripravene pole se odesle bit za bitem na vystup (pozpatku)
          {
            digitalWrite(dinPin, dataPinRegister[i]);
            write_clockPin();                                          // HIGH impulz na CLK
          }


        write_loadPin();                                               // po odeslani vsech 20 bitu se data jednim 'LOAD' impulzem prepisou na vystupy                                   

        delay(1);   
      }                                                                // jde se na dalsi zobrazovaci jednotku
} 


hafca
Příspěvky: 86
Registrován: 23 říj 2017, 23:05
Reputation: 0

Re: Redefinice 2D pole

Příspěvek od hafca » 17 črc 2023, 14:57

Ty OUTy jsem přepsal jak to mám na začátku. Zkusil jsem to zkompilovat, ale na HW zkoušku dojde až pozdě večer. V každám případě dám vědět, jak to dopadlo. A děkuji za pomoc.

AstroMiK
Příspěvky: 593
Registrován: 08 pro 2017, 19:05
Reputation: 0

Re: Redefinice 2D pole

Příspěvek od AstroMiK » 17 črc 2023, 18:03

NE!

Čísla pinů do programu nezadávej.
Podle kat. listu tam zadej čísla 'OUT' v rozsahu 0 až 19.

Trochu problém je, že třeba pin 26 může být OUT0, ale i OUT7. Záleží na tom, jaký konkrétní obvod používáš.

pin-out.gif

hafca
Příspěvky: 86
Registrován: 23 říj 2017, 23:05
Reputation: 0

Re: Redefinice 2D pole

Příspěvek od hafca » 17 črc 2023, 18:28

Používám ten první, to jediná velikost kterou ještě dokážu připájet.
Překopíroval jsem nový blok do programu místo původního a zkusil zkompilovat. To šlo bez chyby, ale přepisovat to dnes už nebudu. Nějak mi to v tom teple nemyslí.

AstroMiK
Příspěvky: 593
Registrován: 08 pro 2017, 19:05
Reputation: 0

Re: Redefinice 2D pole

Příspěvek od AstroMiK » 17 črc 2023, 21:21

EDIT:

Už jsem si všimnul toho spodního komentáře.
Takže by to mělo být takhle:

Kód: Vybrat vše

   //     stary OUT           novy OUT         puvodni funkce
   premapovani[0]         =       11;           // grid 12  
   premapovani[1]         =       10;           // grid 11  
   premapovani[2]         =       9;            // grid 10  
   premapovani[3]         =       8;            // grid 9   
   premapovani[4]         =       7;            // grid 8   
   premapovani[5]         =       6;            // grid 7   
   premapovani[6]         =       5;            // grid 6   
   premapovani[7]         =       4;            // nepouzito (grid 5)
   premapovani[8]         =       3;            // nepouzito (grid 4)
   premapovani[9]         =       2;            // nepouzito (grid 3)
   premapovani[10]        =       1;            // nepouzito (grid 2)
   premapovani[11]        =       0;            // nepouzito (grid 1)
   premapovani[12]         =     12;            // segment A 
   premapovani[13]         =     14;            // segment B
   premapovani[14]         =     17;            // segment C
   premapovani[15]         =     18;            // segment D
   premapovani[16]         =     16;            // segment E
   premapovani[17]         =     13;            // segment F
   premapovani[18]         =     15;            // segment G
   premapovani[19]         =     19;            // segment dp


Kód: Vybrat vše

          Grid 1  Grid 2  Grid 3  Grid 4  Grid 5  Grid 6  Grid 7  Grid 8  Grid 9  Grid 10 Grid 11 Grid 12
původní   OUT11    OUT10    OUT9    OUT8    OUT7    OUT6   OUT5    OUT4    OUT3    OUT2     OUT1   OUT0
nové      OUT0      OUT1    OUT2    OUT3    OUT4    OUT5   OUT6    OUT7    

     
          seg. A  seg. B  seg. C  seg. D  seg. E  seg. F  seg. G  seg. DP
původní   OUT12   OUT13   OUT14   OUT15   OUT16   OUT17   OUT18   OUT19
nové      OUT12   OUT14   OUT17   OUT18   OUT16   OUT13   OUT15   OUT19


Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 60 hostů