Here is the code without having to download it,
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
//#include <TinyWireM.h> // Enable this line if using Adafruit Trinket, Gemma, etc.
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
int pulses, A_SIG=0, B_SIG=1; //encoder inputs pin 2 and 3
//reset value switch
int buttonPressCount;
float (result);
float (result2);
const int buttonPin0 = 11; //the pin that the pushbutton is attached to +100
const int buttonPin1 = 10; //the pin that the pushbutton is attached to +10
const int buttonPin2 = 7; //the pin that the pushbutton is attached to -5
const int buttonPin3 = 13; //the pin that the pushbutton is attached to Setpoint
const int buttonPin4 = 12; //the pin that the pushbutton is attached to reset setpoint
const int buttonPin5 = 6; //the pin that the pushbutton is attached to enable output
const int buttonPin6 = 8; //the pin that the pushbutton is attached to reset pulses count
const int sol = 9; // output solenoid
int buttonPressCounter = 0; //counter for the number of button presses
int buttonState0 = 0; //current state of the button
int buttonState1 = 0; //current state of the button
int buttonState2 = 0; //current state of the button
int buttonState3 = 0; //current state of the button
int buttonState4 = 0; //current state of the button
int buttonState5 = 0; //current state of the button
int buttonState6 = 0; //current state of the button
int lastButtonState0 = 0; //previous state of the button
int lastButtonState1 = 0; //previous state of the button
int lastButtonState2 = 0; //previous state of the button
Adafruit_7segment matrix = Adafruit_7segment();
void setup(){
attachInterrupt(0, A_RISE, RISING);
attachInterrupt(1, B_RISE, RISING);
pinMode(buttonPin0, INPUT); //initialize the button pin as a input + 100
pinMode(buttonPin1, INPUT); //initialize the button pin as a input + 10
pinMode(buttonPin2, INPUT); //initialize the button pin as a input -5
pinMode(buttonPin3, INPUT); //initialize the button pin as a input Setpoint
pinMode(buttonPin4, INPUT); //initialize the button pin as a input reset setpoint
pinMode(buttonPin5, INPUT); //initialize the button pin as a input enable output
pinMode(buttonPin6, INPUT); //initialize the button pin as a input reset pulses count
pinMode(sol, OUTPUT);
#ifndef __AVR_ATtiny85__
Serial.begin(9600);
Serial.println("7 Segment Backpack Test");
Wire.begin();
#endif
matrix.begin(0x70);
}
void loop() {
int val = analogRead(3);
val = map(val, 0, 1023, 0, 15);
matrix.setBrightness(val);
buttonState6 = digitalRead(buttonPin6);
result = pulses * 0.1;
matrix.println(result);
matrix.writeDisplay();
if (buttonState6 == HIGH && digitalRead(buttonPin5)==LOW) {
pulses = 0;
}
while(digitalRead(buttonPin3)==HIGH && digitalRead(buttonPin5)==LOW){
setPoint();
int val = analogRead(3);
val = map(val, 0, 1023, 0, 15);
matrix.setBrightness(val);
result2 = buttonPressCounter * 0.1;
matrix.println(result2);
matrix.writeDisplay();
}
if(digitalRead(buttonPin4)==HIGH && digitalRead(buttonPin5)==LOW){
buttonPressCounter = 0;
}
if(digitalRead(buttonPin5)==HIGH){
automatic();
int pulses;
int buttonPressCounter;
int val = analogRead(3);
val = map(val, 0, 1023, 0, 15);
matrix.setBrightness(val);
matrix.println(result);
matrix.writeDisplay();
}
else{
digitalWrite(sol, LOW);
}
}
void setPoint(){
buttonState0 = digitalRead(buttonPin0); //read the pushbutton input pin
// compare the buttonState to its previous state
if (buttonState0 != lastButtonState0) {
// if the state has changed, increment the counter
if (buttonState0 == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
buttonPressCounter+=100;
}
}
buttonState1 = digitalRead(buttonPin1); //read the pushbutton input pin
if (buttonState1 != lastButtonState1) {
// if the state has changed, increment the counter
if (buttonState1 == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
buttonPressCounter+=10;
}
}
buttonState2 = digitalRead(buttonPin2); //read the pushbutton input pin
if (buttonState2 != lastButtonState2) {
// if the state has changed, increment the counter
if (buttonState2 == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
buttonPressCounter-=5;
}
}
lastButtonState0 = buttonState0; // save the current state as the last state, for next time through the loop
lastButtonState1 = buttonState1; // save the current state as the last state, for next time through the loop
lastButtonState2 = buttonState2; // save the current state as the last state, for next time through the loop
}
void automatic(){
if (pulses < buttonPressCounter){
digitalWrite (sol, HIGH);
}
if (pulses >= buttonPressCounter){
digitalWrite (sol, LOW);
}
}
void A_RISE(){
detachInterrupt(0);
A_SIG=1;
if(B_SIG==0)
pulses++;//moving forward
if(B_SIG==1)
pulses--;//moving reverse
attachInterrupt(0, A_FALL, FALLING);
}
void A_FALL(){
detachInterrupt(0);
A_SIG=0;
if(B_SIG==1)
pulses++;//moving forward
if(B_SIG==0)
pulses--;//moving reverse
attachInterrupt(0, A_RISE, RISING);
}
void B_RISE(){
detachInterrupt(1);
B_SIG=1;
if(A_SIG==1)
pulses++;//moving forward
if(A_SIG==0)
pulses--;//moving reverse
attachInterrupt(1, B_FALL, FALLING);
}
void B_FALL(){
detachInterrupt(1);
B_SIG=0;
if(A_SIG==0)
pulses++;//moving forward
if(A_SIG==1)
pulses--;//moving reverse
attachInterrupt(1, B_RISE, RISING);
}
Adam