Beste Forumleden, ik zit als nieuweling met een probleem. Mijn sketch met besturing van 2 stappenmotors en een solenoïde werkt goed. Echter een apart programma op een Arduino UNO Rev3 en een LCD_i2c voor het tellen van een schakelaar (aan/uit) wil niet werken. De code is toegevoegd. De schakelaars (touchPin en ResetPin) zijn aangesloten op pin 8 en 3 ieder met een pulldown weerstand van 10k. De teller toont slecht 1. Als ik het commando clear uitschakel blijft de teller doorlopen 1,2,enz. E.a. reageert niet op de schakelaars.
Waar zit de bug?? Graag jullie advies.
Code:
/Sketch_mar4a; Code for counting and resetting/
// Start of setting for lcd with i2c
// LiquidCrystal_I2C.h: GitHub - johnrickman/LiquidCrystal_I2C: LiquidCrystal Arduino library for the DFRobot I2C LCD displays
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
// Wiring: SDA pin is connected to A4 and SCL pin to A5.
// Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered)
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); // Change to (0x27,16,2) for 16x2 LCD.
// End of settings for LCD 1602 with I2C
const int touchPin = 8; // Input Pin for touch sensor
const int resetPin = 3; // Resetting
const int touchDelay = 500; // minimum ms between each touch
int count = 0; // variable holding the count number
void setup(){
// initializa the LCD
lcd.init();
lcd.backlight(); // turn backlight on
lcd.print ("Aantal");
lcd.setCursor (0,1);
lcd.print ("ontpitproduct");
Serial.begin(9600); //initialize monitor
Serial.println ("");
pinMode (touchPin, INPUT); // define pin for touchpad
}
void loop(){
int touchValue = digitalRead(touchPin); // read touch pinand store it in touchValue
// if touchValue is HIGH
if(touchPin == HIGH)
delay(500);
{
count++; //increment the count
lcd.clear(); //clean previous value from screen
lcd.print ("Aantal");
lcd.setCursor(0,1);
lcd.print ("ontpit");
lcd.setCursor(9,1);
lcd.print(count);
Serial.print("Aantal");
Serial.println("ontpit");
Serial.print(count);
delay(touchDelay); //touch delay time
}
// if reset switch is pressed
lcd.clear(); // clear previous valus from screen
count = 0; //reset counter
Serial.println ("Counter resetted"); //print info
lcd.setCursor (0,0);
lcd.print ("recounting");
lcd.setCursor (0,1);
lcd.print ("Resetted");
}