Hi there newish to arduino about a month now.
I'm trying to build an heating thermostat so far so good until i started to merge guage code into my project.
Im getting:-
NEW-Touch-Smart-Thermostat-Landscape-Gauge.ino: In function 'void loop()':
NEW-Touch-Smart-Thermostat-Landscape-Gauge:374:3: error: a function-definition is not allowed here before '{' token
{
^
NEW-Touch-Smart-Thermostat-Landscape-Gauge:473:3: error: a function-definition is not allowed here before '{' token
{
^
Below is a copy of my sketch
// #########################################################################
// Draw the meter on the screen, returns x coord of righthand side
// #########################################################################
int ringMeter(int value, int vmin, int vmax, int x, int y, int r, char *units, byte scheme, int old)
{
// .kbv optional old argument only redraws the changed area. 10x speed increase
// .kbv colours are always drawn in numbered segments. map value to the segment number
// Minimum value of r is about 52 before value text intrudes on ring
// drawing the text first is an option
x += r; y += r; // Calculate coords of centre of ring
int w = r / 4; // Width of outer ring is 1/4 of radius
int segnum = 160 / 5; // Half the sweep angle of meter (300 degrees)
int text_colour = 0; // To hold the text colour
int v = map(value, vmin, vmax, -segnum, segnum); // Map the value to an segnum v
byte segdegree = 5; // Segments are 5 degrees wide = 60 segments for 300 degrees
byte inc = 2; // Draw segments every 5 degrees, increase to 10 for segmented ring
int lo, hi;
if (old == -9999) lo = -segnum, hi = segnum;
else {
old = map(old, vmin, vmax, -segnum, segnum);
lo = (old < v) ? old : v;
hi = (old > v) ? old : v;
}
// Draw colour blocks every inc degrees
for (int i = lo; i < hi; i += inc) {
// Choose colour from scheme
int colour = 0;
switch (scheme) {
case 0: colour = ILI9341_RED; break; // Fixed colour
case 1: colour = ILI9341_GREEN; break; // Fixed colour
case 2: colour = ILI9341_BLUE; break; // Fixed colour
case 3: colour = rainbow(map(i, -segnum, segnum, 0, 127)); break; // Full spectrum blue to red
case 4: colour = rainbow(map(i, -segnum, segnum, 63, 127)); break; // Green to red (high temperature etc)
case 5: colour = rainbow(map(i, -segnum, segnum, 127, 63)); break; // Red to green (low battery etc)
default: colour = ILI9341_BLUE; break; // Fixed colour
}
// Calculate pair of coordinates for segment start
float segradian = (i * segdegree - 90) * 0.0174532925;
float sx = cos(segradian);
float sy = sin(segradian);
uint16_t x0 = sx * (r - w) + x;
uint16_t y0 = sy * (r - w) + y;
uint16_t x1 = sx * r + x;
uint16_t y1 = sy * r + y;
// Calculate pair of coordinates for segment end
segradian += segdegree * 0.0174532925;
float sx2 = cos(segradian);
float sy2 = sin(segradian);
int x2 = sx2 * (r - w) + x;
int y2 = sy2 * (r - w) + y;
int x3 = sx2 * r + x;
int y3 = sy2 * r + y;
if (i >= v) colour = ILI9341_GREY; //blank colour
else text_colour = colour; // Save the last colour drawn
// Fill in segments with 2 triangles
tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, colour);
}
// Convert value to a string
char buf[10];
byte len = 4; if (value > 999) len = 5;
#if defined(ARDUINO_ARCH_STM32)
dtostrf(value, len + 2, 0, buf);
char *p = strchr(buf, '.');
if (p != NULL) *p = '\0';
#else
dtostrf(value, len, 0, buf);
#endif
// Set the text colour to default
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
// Uncomment next line to set the text colour to the last segment value!
// tft.setTextColor(text_colour, ILI9341_BLACK);
// .kbv use helper function instead of GFX_AS method
// Print value, if the meter is large then use big font 6, othewise use 4
if (r > 84) drawCentreString(buf, x - 5, y - 20, 6); // Value in middle
else drawCentreString(buf, x - 5, y - 20, 4); // Value in middle
// Print units, if the meter is large then use big font 4, othewise use 2
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
if (r > 84) drawCentreString(units, x, y + 30, 4); // Units display
else drawCentreString(units, x, y + 5, 2); // Units display
// Calculate and return right hand side x coordinate
return x + r;
}
// #########################################################################
// Return a 16 bit rainbow colour
// #########################################################################
unsigned int rainbow(byte value)
{
// Value is expected to be in range 0-127
// The value is converted to a spectrum colour from 0 = blue through to 127 = red
byte red = 0; // Red is the top 5 bits of a 16 bit colour value
byte green = 0;// Green is the middle 6 bits
byte blue = 0; // Blue is the bottom 5 bits
byte quadrant = value / 32;
if (quadrant == 0) {
blue = 31;
green = 2 * (value % 32);
red = 0;
}
if (quadrant == 1) {
blue = 31 - (value % 32);
green = 63;
red = 0;
}
if (quadrant == 2) {
blue = 0;
green = 63;
red = value % 32;
}
if (quadrant == 3) {
blue = 0;
green = 63 - 2 * (value % 32);
red = 31;
}
return (red << 11) + (green << 5) + blue;
}
}
I have been through the code to make sure { has } to close front to back, back to front a 100 times and can not see the error.
Thanks in advance
Shaun