I have been writing some code to draw a linegraph on a LCD screen and trigger an alarm if the analog value is greater than an alarm point.
Everything works as I want.
Graph is drawn on the screen.
The INC and DEC buttons change the alarm level
The bottom RH corner displays the weigh in Kg
The relay turns from on to off when the alarm is exceeded.
I have a function coded to change the Alarm level when the INC and DEC buttons are pressed.
My question is if I leave out the (int Weight) parameter in the following line
int AlarmLevel(int Weight) {
I get a too many parameters error.
I thought I would be able to put
void AlarmLevel () {
as I was not parsing any parameter TO the function, just returning Alarm to the main loop.
So what have I misunderstood about writing a Function?
Thanks
sutto55
// Touch screen library with X Y and Z (pressure) readings as well
// Analog sensor data graph
// Code by Damon Borgnino
#include "TouchScreen.h"
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#define DEBUG
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
// These are the pins for the shield!
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
#define MINPRESSURE 100
#define MAXPRESSURE 1000
// calibration mins and max for raw data when touching edges of screen
// YOU CAN USE THIS SKETCH TO DETERMINE THE RAW X AND Y OF THE EDGES TO GET YOUR HIGHS AND LOWS FOR X AND Y
#define TS_MINX 210
#define TS_MINY 210
#define TS_MAXX 915
#define TS_MAXY 910
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GREY 0xCE79
#define LIGHTGREY 0xDEDB
#define relayPin 40 //will turn on to power sensor(s)
#define sensor1Pin A15 // sensor one
#define sensor2Pin A14 // sensor two
//#define relayPin 40 // Output to turn on relay
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 364);
int sensor1Val = 0; // used to hold sensor data
int sensor1ValOld = 0; // holds previous value for line graph
int Alarm = 110;
int AlarmPoint;
int oldAlarmPoint;
int oldAlarm;
int Xposn = 51, Yposn;
int Weight;
int Kg;
int oldKg = 0;
int plotVal ;
int oldPlotVal;
bool toggle = true;
//int relayPin = 40;
//int Xposn, Yposn;
//TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
//TSPoint p = ts.getPoint();
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define TS_LEFT 200 //920
#define TS_TOP 120 //940
#define TS_RT 920 //200
#define TS_BOT 940 //120
/////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
#ifdef DEBUG
Serial.begin(9600);
#endif // DEBUG
pinMode(relayPin, OUTPUT);
//digitalWrite(powerPin, HIGH); // turn sensor power on
tft.drawRect(50, 0, 319, 200, BLUE);
int i = 0;
// Draw crosshairs {
tft.reset();
delay(500);
uint16_t identifier = tft.readID();
tft.begin(identifier);
delay(500);
tft.fillRect(0, 0, 240, 320, BLACK);
tft.setRotation(3);
tft.drawRect(50, 1, 270, 200, BLUE);
for (int i = 0; i < 200; i += 10) {
tft.drawLine(45, i, 50, i, BLUE);
}
tft.fillRoundRect(10, 205, 50, 30, 8, GREEN);
tft.fillRoundRect(80, 205, 50, 30, 8, GREEN);
tft.setCursor(17, 215);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print("INC");
tft.setCursor(87, 215);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print("DEC");
//tft.setCursor(1, 1);
//tft.setTextColor(BLUE);
//tft.setTextSize(2);
//tft.print("KGs");
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.setCursor(280, 210);
tft.print("Kg");
//tft.drawLine(51, 112, 318, 112, RED);
}
//////////////////////////////////////////////////////////////////////////////////
void loop () {
int AlarmLine;
//Read Value from Strain Gauge and send
//it to Tension Function then return calculated weight.
sensor1Val = analogRead(sensor1Pin);
Kg = sensor1Val / 4.096;
plotVal = 197 - (Kg / 1.28);
tft.drawLine(Xposn, oldPlotVal, Xposn + 1, plotVal, YELLOW);
if (plotVal != oldPlotVal) {
oldPlotVal = plotVal;
}
if ( Kg != oldKg ) {
oldKg = Kg;
tft.fillRect(220, 210, 60, 40, BLACK);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.setCursor(220, 210);
tft.print(Kg);
}
//pinMode(YP, OUTPUT); //.kbv these pins are shared with TFT
//pinMode(XM, OUTPUT);
delay(100);
Xposn = Xposn + 1;
if (Xposn > 317) {
Xposn = 52;
tft.fillRect(51, 2, 268, 197, BLACK);
}
AlarmLine = AlarmLevel (Alarm);
AlarmPoint = (-0.8 * Alarm) + 200 ;
tft.drawLine (52, AlarmPoint, 318, AlarmPoint, RED);
tft.setTextColor(RED);
tft.setTextSize(2);
tft.setCursor(0, (AlarmPoint - 10));
if (Alarm != oldAlarm) {
tft.fillRect(0, (AlarmPoint - 20), 40, 35, BLACK);
tft.print(Alarm);
oldAlarm = Alarm;
}
if (Kg < Alarm) {
tft.fillCircle(160, 220, 15, GREEN);
digitalWrite(relayPin, HIGH);
}
else {
tft.fillCircle(160, 220, 15, RED);
digitalWrite (relayPin, LOW);
}
}
int AlarmLevel(int Weight) {
TSPoint p = ts.getPoint();
pinMode(YP, OUTPUT); //.kbv these pins are shared with TFT
pinMode(XM, OUTPUT);
if (p.z > ts.pressureThreshhold) {
if (p.x > 820 && p.x < 910 && p.y > 150 && p.y < 250) {
tft.drawLine (52, ((-0.8 * Alarm) + 200), 318, ((-0.8 * Alarm) + 200), BLACK);
Alarm = Alarm + 10;
if ( Alarm > 240) {
Alarm = 240;
}
}
if (p.x > 820 && p.x < 920 && p.y > 330 && p.y < 430) {
tft.drawLine (52, ((-0.8 * Alarm) + 200), 318, ((-0.8 * Alarm) + 200), BLACK);
Alarm = Alarm - 10 ;
if (Alarm < 10) {
Alarm = 10;
}
}
return Alarm;
}
}