Salve, ho scritto il seguente codice per Arduino YUN:
#include<AD5231.h>
#include <DigiPot.h>
const int pin0 = 0; // setup the analog pin 0 as an input read out pin
int val = 0; // set up the value for transmission to the MCP4251
// this constant won't change:
const int buttonPin1 = 2; // Pin 2(nonPWM) is attached to the first button
const int buttonPin2 = 4; // Pin 4 (nonPWM) is attached to the second button
const int ledPin1 = 5; // the pin that the LED is attached to
const int ledPin2 = 6; // the pin that LED 2 is attached to
// Variables will change:
int buttonPushCounter1 = 0; // counter for the number of button1 presses
int buttonPushCounter2 = 0; // counter for the number of button2 presses
int potlevel = 0; // This is the counter number that's added to or subtracted from for the digital pot
int steplevel = 0; // The pot's step value from buttonPushCounter1
int button1 = 0;
int button2 = 0;
int buttonState1 = 0; // current state of button1
int buttonState2 = 0; // current state of button 2
int lastButtonState1 = 0; // previous state of button 1
int lastButtonState2 = 0; // previous state of button 2
int potval = 0; // the value initial of the digital p
DigiPot mcp4251(10, 13, 11); //Start a new instance called "mcp4251"
//format: DigiPot <instance>(CS, SCK, SDI), and connect it to the digital outputs of
// 10, 13, and 11 from the Arduino board.
void setup() {
// initialize the button pins as a input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
// initialize the LED as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// initialize the digital pot
mcp4251.clear(0); //clear both pots; they default to 127
mcp4251.clear(1); //format: <instance>.clear(pot)....pot is either 0 or 1
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
val = analogRead(pin0); // read the input from digital pot wiper 0
// read the pushbutton input pin:
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
// compare the buttonState to its previous state
if (buttonState1 != lastButtonState1) {
// if the state has changed, increment the counter
if (buttonState1 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
digitalWrite(ledPin1, HIGH); // And let's indicate the button's being pushed on the led
buttonPushCounter1 = constrain(buttonPushCounter1++, 1, 20); // And increment the counter, but constrain it
}
else {
digitalWrite(ledPin1, LOW); // Turn it off when released
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState1 = buttonState1;
// compare the buttonState2 to its previous state
if (buttonState2 != lastButtonState2) {
// if the state has changed, increment the counter
if (buttonState2 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
digitalWrite(ledPin2, HIGH); // Let's indicate the LED on when button 2 is pressed
buttonPushCounter2 = constrain(buttonPushCounter2++, 1, 20);
}
else {
digitalWrite(ledPin2, LOW); // And shut it off when it's off.
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState2 = buttonState2;
if (buttonPushCounter1 > buttonPushCounter2) {
buttonPushCounter1 = buttonPushCounter1 - buttonPushCounter2;
} else {
buttonPushCounter2 = buttonPushCounter2 - buttonPushCounter1;
}
Serial.println(buttonPushCounter1);
// Serial.println(potlevel);
// if (potlevel < 1) {
// steplevel1 = 1;
// } else {
// steplevel1 = potlevel;
// }
// Serial.println(steplevel1);
// int potval = map(steplevel1, 3, 1023, 1, 255); // map the values from
// the steplevel1 which is 0-1023
// re spread them across 0-255, which is the amount the
// mcp4251 can process
// mcp4251.write(0, potval); // send the value to the digital pot
// Serial.println(val);
ed ottengo il seguente messaggio di errore:
Arduino:1.6.13 (Linux), Scheda:"Arduino Yún"
/home/utente/Desktop/DigiPot()/DigiPot__.ino/DigiPot__.ino.ino:2:21: fatal error: DigiPot.h: No such file or directory
#include <DigiPot.h>
^
compilation terminated.
exit status 1
Errore durante la compilazione per la scheda Arduino Yún.
Ho cercato su internet ma non trovo soluzione.
Avevo installato due librerie Ad5231 ma il problema permane cancellandone una.
Sembra non riconosca DigiPot.h
Sto cercando di pilotare un MCP4251 con lo YUN.
Aiutatemi per favore.