SprintF / DrawText problem - Help :(
SprintF / DrawText problem - Help :(
Hi!
This for some reason stopped working:
char buf[16];
sprintf(buf,"RC %d% +/-%d%",wpWavStr,wpWavOff);
ReefAngel.LCD.DrawText(0,255,15,52,buf);
but this works fine (meaning my wpWavStr & wpWavOff variables are working):
ReefAngel.LCD.DrawText (0,255,15,52,wpWavStr);
ReefAngel.LCD.DrawText (0,255,35,52,"+/-");
ReefAngel.LCD.DrawText (0,255,55,52,wpWavOff);
Can anyone show me where I've gone wrong?
This for some reason stopped working:
char buf[16];
sprintf(buf,"RC %d% +/-%d%",wpWavStr,wpWavOff);
ReefAngel.LCD.DrawText(0,255,15,52,buf);
but this works fine (meaning my wpWavStr & wpWavOff variables are working):
ReefAngel.LCD.DrawText (0,255,15,52,wpWavStr);
ReefAngel.LCD.DrawText (0,255,35,52,"+/-");
ReefAngel.LCD.DrawText (0,255,55,52,wpWavOff);
Can anyone show me where I've gone wrong?
Re: SprintF / DrawText problem - Help :(
Oh, my array is large, buddy! (just kidding, had to)rimai wrote:Make sure you got a large enough array.
Sorry, I am new to the sprintf function.
I did change char buf[16]; to char buf[32]; but it didn't help.
To be specific - it is displaying "RC 55" and not the rest of the line.
Re: SprintF / DrawText problem - Help :(
sure.rimai wrote:Can you post the entire code?
I'm having more problems, Roberto. Sorry, I'm a n00b.
My wpMode is incorrect. It's 9:28 here, I should be on mode 2 but it is in mode 3.
Code: Select all
//// Port 1 Heater
//// Port 2 ATO pump
//// Port 3 Reactor Pump
//// Port 4 Protien Skimmer
//// Port 5 Return Pump
//// Port 6 Wavemaker
//// Port 7 UV Sterilizer
//// Port 8 Fuge Light
//// Always on - Lights & Salinity Module
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <DCPump.h>
#include <ReefAngel.h>
////// Place global variable code below here
#define Heater Port1
#define Topoff Port2
#define Reactor Port3
#define Skimmer Port4
#define Return Port5
#define Wave Port6
#define UVlight Port7
#define Fugelight Port8
#define FugelightBit 1<<7
#define UVlightBit 1<<6
#define WaveBit 1<<5
#define ReturnBit 1<<4
#define SkimmerBit 1<<3
#define ReactorBit 1<<2
#define TopoffBit 1<<1
#define HeaterBit 1<<0
byte wpMode;
byte wpWavStr;
byte wpWavOff;
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = TopoffBit | ReactorBit | SkimmerBit | ReturnBit | UVlightBit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = HeaterBit | TopoffBit | ReactorBit | SkimmerBit | ReturnBit | WaveBit | UVlightBit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = FugelightBit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = HeaterBit | TopoffBit | ReactorBit | SkimmerBit | ReturnBit | WaveBit | UVlightBit;
// Use T1 (SUMP) probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Ports that are always on
ReefAngel.Relay.On( Return );
ReefAngel.Relay.On( Reactor );
ReefAngel.Relay.On( Wave );
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.StandardHeater( Heater );
ReefAngel.StandardATO( Topoff );
ReefAngel.MoonLights( Fugelight );
////// Place your custom code below here
ReefAngel.LCD.DrawText(0,255,20,80,"Joe's Reef Tank");
ReefAngel.Relay.DelayedOn(Skimmer,2);
ReefAngel.Relay.DelayedOn(UVlight,1);
ReefAngel.DCPump.FeedingSpeed=30;
ReefAngel.DCPump.WaterChangeSpeed=0;
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.ActinicChannel = AntiSync;
if (ReefAngel.DCPump.Mode==Custom) ReefAngel.DCPump.UseMemory = false;
else ReefAngel.DCPump.UseMemory = true;
// Custom Wave Routine
if (ReefAngel.DCPump.Mode==Custom) {
// set the wpMode
if ( (hour() >= 5) && (hour() < 8) ) wpMode=1; // from 5am - 8am
if ( (hour() >= 8) && (hour() < 11) ) wpMode=2; // from 8am - 11am
if ( (hour() >= 11) && (hour() < 14) ) wpMode=3; // from 11a - 2pm
if ( (hour() >= 14) && (hour() < 17) ) wpMode=2; // from 2pm - 5pm
if ( (hour() >= 17) && (hour() < 20) ) wpMode=1; // from 5pm - 8pm
if ( (hour() >= 20) && (hour() < 23) ) wpMode=2; // from 8pm - 11p
if ( (hour() >= 23) && (hour() < 2) ) wpMode=3; // from 11pm - 2am
if ( (hour() >= 2) && (hour() < 5) ) wpMode=2; // from 2am - 5am
// Set Wave Str
if (wpMode=1) wpWavStr=45;
if (wpMode=2) wpWavStr=50;
if (wpMode=3) wpWavStr=55;
//Set the Wave OffSet
wpWavOff=12;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) wpWavStr=30; wpWavOff=0;
ReefAngel.DCPump.SetMode( ReefCrest,wpWavStr,wpWavOff );
//char buf[16];
//sprintf(buf,"RC %d% +/-%d%",wpWavStr,wpWavOff);
//ReefAngel.LCD.DrawText(0,255,15,52,buf);
ReefAngel.LCD.DrawText (0,255,15,52,wpWavStr);
ReefAngel.LCD.DrawText (0,255,35,52,"+/-");
ReefAngel.LCD.DrawText (0,255,55,52,wpWavOff);
}
// end Custom Wave Routine
// Only turn on UV Sterilizer between 11pm and 5am
if ( (hour() >= 5) && (hour() < 23) ) // from 5a - 11p
ReefAngel.Relay.Off(UVlight);
else ReefAngel.Relay.On(UVlight);
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "Smotz" );
ReefAngel.ShowInterface();
}
void DrawCustomMain()
{
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();
// Salinity
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,15,66, "SAL:" );
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,39,66, ReefAngel.Params.Salinity );
pingSerial();
// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 93, TempRelay );
pingSerial();
// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}
void DrawCustomGraph()
{
}
Re: SprintF / DrawText problem - Help :(
Your code says mode 2:
if ( (hour() >= 20) && (hour() < 23) ) wpMode=2; // from 8pm - 11p
if ( (hour() >= 20) && (hour() < 23) ) wpMode=2; // from 8pm - 11p
Roberto.
Re: SprintF / DrawText problem - Help :(
I didn't know why either, but google is your friend
https://www.allegro.cc/forums/thread/591765
The % is indicator of a string input element, so you must tell sprint that you want the % sign.
https://www.allegro.cc/forums/thread/591765
The % is indicator of a string input element, so you must tell sprint that you want the % sign.
Code: Select all
sprintf(buf,"RC %d%% +/- %d%%",wpWavStr,wpWavOff);
Roberto.
Re: SprintF / DrawText problem - Help :(
yes but mode 2 my wpWavStr should be 50 but the display out put it showing its 55rimai wrote:Your code says mode 2:
if ( (hour() >= 20) && (hour() < 23) ) wpMode=2; // from 8pm - 11p
I added a wpMode=1; before the if wpmode statements but it is still saying its mode 3. Huh.
Code: Select all
if (wpMode=1) wpWavStr=45;
if (wpMode=2) wpWavStr=50;
if (wpMode=3) wpWavStr=55;
ReefAngel.LCD.DrawText (0,255,15,80,wpMode);
//Set the Wave OffSet
wpWavOff=12;
//if (ReefAngel.DisplayedMenu==FEEDING_MODE) wpWavStr=30; wpWavOff=0;
ReefAngel.DCPump.SetMode( ReefCrest,wpWavStr,wpWavOff );
Last edited by Smotz on Fri Jun 21, 2013 6:57 pm, edited 1 time in total.
Re: SprintF / DrawText problem - Help :(
Nice. That worked. Thank you - i did google but I think I just didn't understand.rimai wrote:I didn't know why either, but google is your friend
https://www.allegro.cc/forums/thread/591765
The % is indicator of a string input element, so you must tell sprint that you want the % sign.Code: Select all
sprintf(buf,"RC %d%% +/- %d%%",wpWavStr,wpWavOff);
Re: SprintF / DrawText problem - Help :(
This is not a comparison. It's an assignment:
It should be like this:
Code: Select all
if (wpMode=1) wpWavStr=45;
if (wpMode=2) wpWavStr=50;
if (wpMode=3) wpWavStr=55;
Code: Select all
if (wpMode==1) wpWavStr=45;
if (wpMode==2) wpWavStr=50;
if (wpMode==3) wpWavStr=55;
Roberto.
Re: SprintF / DrawText problem - Help :(
rimai wrote:This is not a comparison. It's an assignment:It should be like this:Code: Select all
if (wpMode=1) wpWavStr=45; if (wpMode=2) wpWavStr=50; if (wpMode=3) wpWavStr=55;
Code: Select all
if (wpMode==1) wpWavStr=45; if (wpMode==2) wpWavStr=50; if (wpMode==3) wpWavStr=55;
Holy Crap! That did it - you fixed everything. Again, Thank you.