so continued from the post above
I added code from the fade sketch to make
#include <TFT.h> // Arduino TFT library
#include <SPI.h>
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
// Specify the pins for the two counter reset buttons and indicator LED
byte sensorInterrupt = 0; // 0 = pin 2; 1 = pin 3
byte sensorPin = 2;
// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.5;
volatile byte pulseCount;
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitresA;
unsigned long totalMilliLitresB;
unsigned long oldTime;
int rppin = 3; // the pin that the RimsPump is attached to
int pumpspeed = 0; // how bright the LED is
int RampAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(rppin, OUTPUT);
{
TFTscreen.begin();
TFTscreen.background(0,0,0);
TFTscreen.stroke(255,255,255);
TFTscreen.setTextSize(3);
pinMode(rppin, OUTPUT);
// Initialize a serial connection for reporting values to the host
Serial.begin(9600);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitresA = 0.0;
totalMilliLitresB = 0.0;
oldTime = 0;
// The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
// Configured to trigger on a FALLING state change (transition from HIGH
// state to LOW state)
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
void loop() {
// put your main code here, to run repeatedly:
if((millis() - oldTime) > 1000) // Only process counters once per second
{
// Disable the interrupt while calculating flow rate and sending the value to
// the host
detachInterrupt(sensorInterrupt);
// Because this loop may not complete in exactly 1 second intervals we calculate
// the number of milliseconds that have passed since the last execution and use
// that to scale the output. We also apply the calibrationFactor to scale the output
// based on the number of pulses per second per units of measure (litres/minute in
// this case) coming from the sensor.
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
// Note the time this processing pass was executed. Note that because we've
// disabled interrupts the millis() function won't actually be incrementing right
// at this point, but it will still return the value it was set to just before
// interrupts went away.
oldTime = millis();
// Divide the flow rate in litres/minute by 60 to determine how many litres have
// passed through the sensor in this 1 second interval, then multiply by 1000 to
// convert to millilitres.
flowMilliLitres = (flowRate / 60) * 1000;
// Add the millilitres passed in this second to the cumulative total
totalMilliLitresA += flowMilliLitres;
totalMilliLitresB += flowMilliLitres;
// During testing it can be useful to output the literal pulse count value so you
// can compare that and the calculated flow rate against the data sheets for the
// flow sensor. Uncomment the following two lines to display the count value.
// Serial.print(pulseCount, DEC);
//Serial.print(" ");
// Write the calculated value to the serial port. Because we want to output a
// floating point value and print() can't handle floats we have to do some trickery
// to output the whole number part, then a decimal point, then the fractional part.
unsigned int frac;
// Print the flow rate for this second in litres / minute
Serial.print(int(flowRate)); // Print the integer part of the variable
Serial.print("."); // Print the decimal point
// Determine the fractional part. The 10 multiplier gives us 1 decimal place.
frac = (flowRate - int(flowRate)) * 10;
Serial.print(frac, DEC) ; // Print the fractional part of the variable
// Print the number of litres flowed in this second
Serial.print(" "); // Output separator
Serial.print(flowMilliLitres);
// Print the cumulative total of litres flowed since starting
Serial.print(" "); // Output separator
Serial.print(totalMilliLitresA);
Serial.print(" "); // Output separator
Serial.println(totalMilliLitresB);
TFTscreen.stroke(255,255,255);
TFTscreen.text("Flow:",0,0);
if(int(flowRate) < 10)
{
}
TFTscreen.text("",0,30),
TFTscreen.print((int)flowRate); // Print the integer part of the variable
TFTscreen.text(".",0,30); // Print the decimal point
TFTscreen.print(frac, DEC) ; // Print the fractional part of the variable
TFTscreen.text(" L/Min",55,30);
TFTscreen.text("",0,70);
TFTscreen.print(int(totalMilliLitresA / 1000));
TFTscreen.print("L");
TFTscreen.text("",70,70);
TFTscreen.print(int(totalMilliLitresB / 1000));
TFTscreen.print("L");
// Reset the pulse counter so we can start incrementing again
pulseCount = 0;
// Enable the interrupt again now that we've finished sending output
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
}
/**
* Invoked by interrupt0 once per rotation of the hall-effect sensor. Interrupt
* handlers should be kept as small as possible so they return quickly.
*/
void pulseCounter()
{
// Increment the pulse counter
pulseCount++;
}
// set the brightness of pin 9:
analogWrite(rppin, pumpspeed);
// change the brightness for next time through the loop:
pumpspeed = pumpspeed + RampAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}
This get the error message
Arduino: 1.5.6-r2 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
Build options changed, rebuilding all
Using library TFT in folder: C:\Program Files (x86)\Arduino\libraries\TFT
Using library SPI in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI (legacy)
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\mega -IC:\Program Files (x86)\Arduino\libraries\TFT\src -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI C:\Users\Pete\AppData\Local\Temp\build131039157258798746.tmp\sketch_may13b.cpp -o C:\Users\Pete\AppData\Local\Temp\build131039157258798746.tmp\sketch_may13b.cpp.o
sketch_may13b.ino: In function 'void setup()':
sketch_may13b.ino:74: error: 'pulseCounter' was not declared in this scope
sketch_may13b.ino:79: error: a function-definition is not allowed here before '{' token
sketch_may13b.ino:197: error: expected `}' at end of input
Why do i get ": error: 'pulseCounter' was not declared in this scope" in one but not the other ?
Pesh
Im i missing some thing ?
the other errors in guessing are because i copied a { or a } from the other sketch and i have too many now