Arduino-nybörjarfrågor för AquaLight

C, C++, Pascal, Assembly, Raspberry, Java, Matlab, Python, BASIC, SQL, PHP, etc.
Användarvisningsbild
NULL
Inlägg: 2522
Blev medlem: 15 september 2010, 12:59:25
Ort: Örebro

Arduino-nybörjarfrågor för AquaLight

Inlägg av NULL »

Jag har tagit exemplet LiquidCrystal->CustomCharacter och moddat det till att visa nio nivåer på en LCD, som ska representera ljusstyrkan i mitt akvarium.
Men jag får inte till 0%, som istället visar 100%, nån som kan leda mig i rätt riktning?

Kod: Markera allt

/*
  LiquidCrystal Library - Custom Characters

 Demonstrates how to add custom characters on an LCD  display.
 The LiquidCrystal library works with all LCD displays that are
 compatible with the  Hitachi HD44780 driver. There are many of
 them out there, and you can usually tell them by the 16-pin interface.

 This sketch prints "I <heart> Arduino!" and a little dancing man
 to the LCD.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K potentiometer:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 * 10K poterntiometer on pin A0

 created 21 Mar 2011
 by Tom Igoe
 modified 11 Nov 2013
 by Scott Fitzgerald
 modified 7 Nov 2016
 by Arturo Guadalupi

 Based on Adafruit's example at
 https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde

 This example code is in the public domain.
 http://www.arduino.cc/en/Tutorial/LiquidCrystalCustomCharacter

 Also useful:
 http://icontexto.com/charactercreator/

*/

// include the library code:
#include <LiquidCrystal.h>
// Include NewLiquidCrystal Library for I2C

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// make some custom characters:
byte zero[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

byte thirteen[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111
};

byte twentyfive[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111
};

byte thirtyeight[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111
};

byte fifty[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};

byte sixtythree[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111 
};

byte seventyfive[8] = {
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};

byte eightyeight[8] = {
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};

byte hundred[8] = {
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};

void setup() {
  // initialize LCD and set up the number of columns and rows:
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  
  lcd.createChar(0, zero);
  lcd.createChar(1, thirteen);
  lcd.createChar(2, twentyfive);
  lcd.createChar(3, thirtyeight);
  lcd.createChar(4, fifty);
  lcd.createChar(5, sixtythree);
  lcd.createChar(6, seventyfive);
  lcd.createChar(7, eightyeight);
  lcd.createChar(8, hundred);
  
  // set the cursor to the top left
  lcd.setCursor(0, 0);
  //Light
  //lcd.backlight();

  
  // Print a message to the lcd.
  lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
  //lcd.write(" "); funkar ju, varför funkar inte raden ovanför?
  lcd.write(byte(1));
  lcd.write(byte(2));
  lcd.write(byte(3));
  lcd.write(byte(4));
  lcd.write(byte(5));
  lcd.write(byte(6));
  lcd.write(byte(7));
  lcd.write(byte(8));
  lcd.write(byte(7));
  lcd.write(byte(6));
  lcd.write(byte(5));
  lcd.write(byte(4));
  lcd.write(byte(3));
  lcd.write(byte(2));
  lcd.write(byte(1));
    
}

void loop() {
  // read the potentiometer on A0:
  //int sensorReading = analogRead(A0);
  // map the result to 200 - 1000:
  //int delayTime = map(sensorReading, 0, 1023, 200, 1000);
  // set the cursor to the bottom row, 5th position:

  //lcd.write(4);
  //delay(delayTime);

}
Du har inte behörighet att öppna de filer som bifogats till detta inlägg.
Zkronk
Inlägg: 1423
Blev medlem: 23 augusti 2005, 16:44:36
Ort: Uppsala

Re: Arduino-nybörjarfrågor för AquaLight

Inlägg av Zkronk »

Det är väl bara 8 st custom-tecken en HD44780-kompatibel LCD stödjer?
Du försöker ju stoppa i 9 st tecken...

Det finns heller ingen anledning att ha det blanka tecknet för noll, ta symbolen för ett vanligt blanksteg i stället.
Användarvisningsbild
NULL
Inlägg: 2522
Blev medlem: 15 september 2010, 12:59:25
Ort: Örebro

Re: Arduino-nybörjarfrågor för AquaLight

Inlägg av NULL »

Är det max åtta alltså?
Jag har ju testat redan med ditt förslag, som naturligtvis funkar, men ganska osnyggt tillsammans med de andra åtta...
//lcd.write(" "); funkar ju, varför funkar inte raden ovanför?
Zkronk
Inlägg: 1423
Blev medlem: 23 augusti 2005, 16:44:36
Ort: Uppsala

Re: Arduino-nybörjarfrågor för AquaLight

Inlägg av Zkronk »

Enligt https://www.arduino.cc/en/Reference/Liq ... CreateChar i alla fall.
Up to eight characters of 5x8 pixels are supported (numbered 0 to 7).
Användarvisningsbild
sodjan
EF Sponsor
Inlägg: 43148
Blev medlem: 10 maj 2005, 16:29:20
Ort: Söderköping
Kontakt:

Re: Arduino-nybörjarfrågor för AquaLight

Inlägg av sodjan »

" " är ju inte detsamma som en 0 (null).

Ett blanksteg/space är x'20' och ett space är x'00'.

Och ja, HD44780 har 8 egen definierade tecken.
Användarvisningsbild
Icecap
Inlägg: 26105
Blev medlem: 10 januari 2005, 14:52:15
Ort: Aabenraa, Danmark

Re: Arduino-nybörjarfrågor för AquaLight

Inlägg av Icecap »

Sedan är problemet att de egendefinierade tecken uppträder på två platser: 0x00-0x07 och 0x08-0x0F. Men det är samma tecken på 0x00 som på 0x08 osv.
Skriv svar