mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-02 13:24:12 +01:00
a46259a0cf
Still missing: - updates to WiFi lib for sam. - updates to examples of Ehternet and WiFi for sam. Merge remote-tracking branch 'arduino/master' into ide-1.5.x Conflicts: app/src/processing/app/Base.java app/src/processing/app/Editor.java app/src/processing/app/helpers/FileUtils.java app/src/processing/app/i18n/Resources_fr.po app/src/processing/app/i18n/Resources_fr.properties build/shared/revisions.txt hardware/arduino/avr/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino hardware/arduino/avr/libraries/WiFi/examples/WifiChatServer/WifiChatServer.ino hardware/arduino/avr/libraries/WiFi/examples/WifiPachubeClient/WifiPachubeClient.ino hardware/arduino/avr/libraries/WiFi/examples/WifiPachubeClientString/WifiPachubeClientString.ino hardware/arduino/avr/libraries/WiFi/examples/WifiTwitterClient/WifiTwitterClient.ino hardware/arduino/avr/libraries/WiFi/examples/WifiUdpSendReceiveString/WifiUdpSendReceiveString.ino hardware/arduino/avr/libraries/WiFi/examples/WifiWebClient/WifiWebClient.ino hardware/arduino/avr/libraries/WiFi/examples/WifiWebClientRepeating/WifiWebClientRepeating.ino hardware/arduino/avr/libraries/WiFi/examples/WifiWebServer/WifiWebServer.ino libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino libraries/WiFi/examples/WiFiPachubeClient/WiFiPachubeClient.ino libraries/WiFi/examples/WiFiPachubeClientString/WiFiPachubeClientString.ino libraries/WiFi/examples/WiFiTwitterClient/WiFiTwitterClient.ino libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino libraries/WiFi/examples/WifiChatServer/WifiChatServer.ino libraries/WiFi/examples/WifiPachubeClient/WifiPachubeClient.ino libraries/WiFi/examples/WifiPachubeClientString/WifiPachubeClientString.ino libraries/WiFi/examples/WifiTwitterClient/WifiTwitterClient.ino libraries/WiFi/examples/WifiUdpSendReceiveString/WifiUdpSendReceiveString.ino libraries/WiFi/examples/WifiWebClient/WifiWebClient.ino libraries/WiFi/examples/WifiWebClientRepeating/WifiWebClientRepeating.ino libraries/WiFi/examples/WifiWebServer/WifiWebServer.ino
72 lines
1.9 KiB
C++
72 lines
1.9 KiB
C++
/*
|
|
Digital Pot Control
|
|
|
|
This example controls an Analog Devices AD5206 digital potentiometer.
|
|
The AD5206 has 6 potentiometer channels. Each channel's pins are labeled
|
|
A - connect this to voltage
|
|
W - this is the pot's wiper, which changes when you set it
|
|
B - connect this to ground.
|
|
|
|
The AD5206 is SPI-compatible,and to command it, you send two bytes,
|
|
one with the channel number (0 - 5) and one with the resistance value for the
|
|
channel (0 - 255).
|
|
|
|
The circuit:
|
|
* All A pins of AD5206 connected to +5V
|
|
* All B pins of AD5206 connected to ground
|
|
* An LED and a 220-ohm resisor in series connected from each W pin to ground
|
|
* CS - to digital pin 10 (SS pin)
|
|
* SDI - to digital pin 11 (MOSI pin)
|
|
* CLK - to digital pin 13 (SCK pin)
|
|
|
|
created 10 Aug 2010
|
|
by Tom Igoe
|
|
|
|
Thanks to Heather Dewey-Hagborg for the original tutorial, 2005
|
|
|
|
*/
|
|
|
|
|
|
// inslude the SPI library:
|
|
#include <SPI.h>
|
|
|
|
|
|
// set pin 10 as the slave select for the digital pot:
|
|
const int slaveSelectPin = 10;
|
|
|
|
void setup() {
|
|
// set the slaveSelectPin as an output:
|
|
pinMode (slaveSelectPin, OUTPUT);
|
|
// initialize SPI:
|
|
SPI.begin();
|
|
}
|
|
|
|
void loop() {
|
|
// go through the six channels of the digital pot:
|
|
for (int channel = 0; channel < 6; channel++) {
|
|
// change the resistance on this channel from min to max:
|
|
for (int level = 0; level < 255; level++) {
|
|
digitalPotWrite(channel, level);
|
|
delay(10);
|
|
}
|
|
// wait a second at the top:
|
|
delay(100);
|
|
// change the resistance on this channel from max to min:
|
|
for (int level = 0; level < 255; level++) {
|
|
digitalPotWrite(channel, 255 - level);
|
|
delay(10);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void digitalPotWrite(int address, int value) {
|
|
// take the SS pin low to select the chip:
|
|
digitalWrite(slaveSelectPin,LOW);
|
|
// send in the address and value via SPI:
|
|
SPI.transfer(address);
|
|
SPI.transfer(value);
|
|
// take the SS pin high to de-select the chip:
|
|
digitalWrite(slaveSelectPin,HIGH);
|
|
}
|