Ho il mio codice. Che funziona egregiamente su breadboard perchè uso le resistenze da 10kohm sui bottoni.
Sulla shield che h queste resistenze non ci sono, mi è stato detto di Abilitare la resistenza interna pull up per i pin usati con una cosa simile a digitalWrite(button_pin, HIGH);
però nn so come si fa e dove va messo nel mio codice. Sapete aiutarmi?
è esattamente quello che devi fare, se imposti un PIn come INPUT e poi col digitalWrite mandi un HIGH (in setup) la resistenza è automaticamente abilitata.
Quindi modificando il codice così e mettendo OUTPUT invece di INPUT ho abilitato la resistenza interna!?
// fadeTimerFreq is the clock speed in milliseconds, lower numbers are faster
const int fadeTimerFreq = 20;
// fadeTime is the total time it will take to complete the ease (in milliseconds)
const int fadeTime = 3000;
// <<
// additional variable for the timer
int currentTime, fadeTimerLast;
// these constant variables store the pin numbers
const int ledPin = 11;
const int buttonPin = 5; //Incrementa
const int decrisePin = 10; //Decrementa
const int fadeRange = 254;
// the amount to step the fade; must be between 1 and the fadeRange
const float fadeStep = (float(fadeTimerFreq) / (fadeTime)) * fadeRange;
int buttonValue, fadeTarget, fadeValueTweened;
float fadeValue;
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 7, 6, 2, 4);
void setup() {
// initialize the serial port; needed for debugging below
lcd.begin(16, 2);
lcd.print("Fan Speed");
// initialize the LED pin
pinMode(ledPin, OUTPUT);
// initialize the input pin
pinMode(buttonPin, OUTPUT);
pinMode(decrisePin, OUTPUT); //Prova
digitalWrite(5,HIGH);
digitalWrite(10,HIGH);
}
void loop() {
// for all timers
currentTime = millis();
// checks to see if the number of milliseconds has passed
if ( abs(currentTime - fadeTimerLast) >= fadeTimerFreq) {
fadeTimerLast = currentTime;
// read the value from the input incrementa Pin 8
buttonValue = digitalRead(buttonPin);
// step the fading
if(buttonValue == 1){
// if the button is pressed, increase the fade
fadeValue = fadeValue + fadeStep;
}
// read the value from the input decrementa Pin 7
buttonValue = digitalRead(decrisePin); //Prova
// if the button is pressed, decrease the fade
if(buttonValue == 1){
fadeValue = fadeValue - fadeStep;
}
// constrain the fadeValue so it can't go off toward infinity
fadeValue = constrain(fadeValue, 0, fadeRange);
// get the tweened value -- i.e. the smooth value
fadeValueTweened = Quad_easeInOut(fadeValue, 0, fadeRange);
// use the tweened value to set the brightness of the LED
analogWrite(ledPin, fadeValueTweened);
// print the values to the serial port for debugging
lcd.setCursor(0, 1);
lcd.print(fadeValue);
}
}
// Quad easing thanks to Robert Penner
// variables used are type "float" so that you can throw smaller numbers at it and it will still work well
float Quad_easeInOut(float t, float fixedScaleStart, float fixedScaleEnd){
//float b = 0, c = 1, d = 1;
float b = fixedScaleStart;
float c = fixedScaleEnd - fixedScaleStart;
float d = fixedScaleEnd;
if ((t/=d/2) < 1) return c/2*t*t + b;
return -c/2 * ((--t)*(t-2) - 1) + b;
}
Penso che non ci siamo capiti. Tu vuoi usare uno o più pin digitali come ingressi e ti serve che abbiano una resistenza di pull-up; finora l'hai usata esternamente ora vuoi abilitare quella interna, è così?
Se è cosi, devi fare, tutto in Setup
pinMode (5, INPUT)
pinMode (10, INPUT)
digitalWrite (5, HIGH)
digitalWrite (10, HIGH)
al posto di 5 e 10 puoi mettere i nomi delle costanti che hai definito, ok?