int read_encoder();
That is a function definition inside another function (loop()). You cannot have a function definition inside another function. Move the function out of loop(). Remove the semicolon from the end.
int read_encoder()
{
static int8_t enc_states[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
static uint8_t old_AB = 0;
old_AB <<= 2; //remember previous state
old_AB |= ( ENC_PORT & 0x03 ); //add current state
return ( enc_states[( old_AB & 0x0f )]);
}
Then you can call the function with the existing:
tmpdata = read_encoder();
This compiles but is untested:
//Rotary encoder
#define ENC_A 14
#define ENC_B 15
#define ENC_PORT PINC
float benzin; //this variable will be changed by encoder input
float fuel = 0;
float zaehler = 0;
int set = 0; // soetwas nennt man auch "Merker"
int read_encoder();
//flowmeter
#include "LiquidCrystal.h"
LiquidCrystal lcd(7, 8, 9, 12, 11, 10);
// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 2
// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
//switch
const int buttonPin = 4; // the number of the pushbutton pin
const int ledPin = 5; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
// rotary encoder variables Setup encoder pins as inputs */
pinMode(ENC_A, INPUT);
digitalWrite(ENC_A, HIGH);
pinMode(ENC_B, INPUT);
digitalWrite(ENC_B, HIGH);
Serial.begin (115200);
Serial.println("Start");
//float tmpdata;
float benzin = 0;
float fuel;
// flowsensor variables
Serial.print("Flow sensor test!");
lcd.begin(16, 2);
pinMode(FLOWSENSORPIN, INPUT);
digitalWrite(FLOWSENSORPIN, HIGH);
lastflowpinstate = digitalRead(FLOWSENSORPIN);
boolean useInterrupt(true);
// button variables
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop()
{
/////////////////status switch//////////////////////
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);// check if the pushbutton is pressed. if it is, the buttonState is HIGH:
if (buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);// turn LED on:
// bei gedrücktem button anzeige mit rotary encoder erhöhen wenn rotary gedreht wird
///////rotary encoder///////////////////////////////////////////////////////
//static uint8_t benzin = 0; //this variable will be changed by encoder input
float tmpdata;
//float read_encoder();
tmpdata = read_encoder();
if ( tmpdata )
{
Serial.print("Benzin: ");
Serial.println(fuel);
benzin += tmpdata;
benzin = constrain(benzin, 0, 150); // 150 entspricht 15 litern tankinhalt
fuel = benzin / 10;
}
//function returns change in encoder state (-1,0,1)
int encoderValue = read_encoder();
}
else
{
// turn LED off:
digitalWrite(ledPin, LOW);
// wenn button losgelassen nehme fuel und substrahiere permanent den verbrauch
////////// flowmeter /////////////////////////////////
lcd.setCursor(0, 0);
lcd.print("Pu:"); lcd.print(pulses, DEC);
lcd.print(" l/h:"); lcd.print(flowrate);
Serial.print("Freq: "); Serial.println(flowrate);
Serial.print("Pulses: "); Serial.println(pulses);
float fuel = pulses;
fuel /= 1920;
//liters = 15-liters;
flowrate = flowrate * 0, 5194;
//liters /= 60.0;
Serial.print(fuel); Serial.println("l Benzin");
lcd.setCursor(0, 1);
lcd.print(fuel); lcd.print(" l Benzin");
delay(1000);
}
}
int read_encoder()
{
static int8_t enc_states[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
static uint8_t old_AB = 0;
old_AB <<= 2; //remember previous state
old_AB |= ( ENC_PORT & 0x03 ); //add current state
return ( enc_states[( old_AB & 0x0f )]);
}