Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: prphntm63/DS1844
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: LinnesLab/DS1844
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 5 commits
  • 4 files changed
  • 1 contributor

Commits on Jul 29, 2020

  1. added gitignore

    Orlando Hoilett authored and Orlando Hoilett committed Jul 29, 2020
    Copy the full SHA
    18050eb View commit details
  2. switch int to int16_t types

    Orlando Hoilett authored and Orlando Hoilett committed Jul 29, 2020
    Copy the full SHA
    b7b8491 View commit details
  3. added Wire.begin to .ino code

    Orlando Hoilett authored and Orlando Hoilett committed Jul 29, 2020
    Copy the full SHA
    a331238 View commit details
  4. mask 6 bits to return potentiometer value not all 8 bytes

    Orlando Hoilett authored and Orlando Hoilett committed Jul 29, 2020
    Copy the full SHA
    067e8ab View commit details
  5. made some more comments on the .ino

    Orlando Hoilett authored and Orlando Hoilett committed Jul 29, 2020
    Copy the full SHA
    82badb3 View commit details
Showing with 61 additions and 23 deletions.
  1. +14 −0 .gitignore
  2. +34 −13 DS1844.cpp
  3. +4 −4 DS1844.h
  4. +9 −6 examples/DS1844_example/DS1844_example.ino
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ignore Mac DS_Store files in all directories
.DS_Store


#Ignore EAGLE board and schematic auto save files (.b#x and .s#x) in all directories
*.b#?
*.s#?
*.l#?
*.d#?


#Development file for making local changes to Arduino libraries
#Ignore in all directories
.development
47 changes: 34 additions & 13 deletions DS1844.cpp
Original file line number Diff line number Diff line change
@@ -2,14 +2,24 @@
DS1844.h - Library for controlling a Maxim Integrated DS1844 Quad Digital Potentiometer
Created by Matt Westwick; March 23, 2013
Released into the public domain.
UPDATES
2020/07/29:1544> (UTC-5)
- changed "int" to "int16_t". int is a signed 4-byte value on Arduino
Due and SAMD boards, while int is a signed 2-byte value on ATmega-
based boards which could cause some inconsistent behavior across
different architectures. (editor: Orlando S. Hoilett).
*/



#include "Arduino.h"
#include "Wire.h"
#include "DS1844.h"


DS1844::DS1844(int address)
DS1844::DS1844(int16_t address)
{
Wire.begin();
this->address=address;
@@ -22,7 +32,7 @@ DS1844::DS1844(int address)
*/
}

void DS1844::write(int pot, int value) { //value is between 0 and 63
void DS1844::write(int16_t pot, int16_t value) { //value is between 0 and 63

if (value > 63) { //prevents values that are too large from overwriting address bits
value = 63;
@@ -43,15 +53,26 @@ void DS1844::write(int pot, int value) { //value is between 0 and 63
Wire.endTransmission();
}

int DS1844::read(int pot) {
int PotRead[4];
int j = 0;
int address = this->address;
Wire.requestFrom(address, 4);
while (Wire.available()) {
PotRead[j] = Wire.read();
j++;
}

return PotRead[pot];

int16_t DS1844::read(int16_t pot)
{
int16_t PotRead[4];
int16_t j = 0;
int16_t address = this->address;


Wire.requestFrom(address, 4);
while (Wire.available())
{
PotRead[j] = Wire.read();
j++;
}


//moving bits by 2 based on comment from Reddit user: AGeekNamedRoss
//https://www.reddit.com/r/arduino/comments/99dxe2/digital_potentiometer_ds1844_with_arduino/
//Another GitHub user also noticed this problem
//https://github.com/RossJacobs/DS1844
return (PotRead[pot] & (0x3F));
}

8 changes: 4 additions & 4 deletions DS1844.h
Original file line number Diff line number Diff line change
@@ -11,11 +11,11 @@

class DS1844
{
int address;
int16_t address;
public:
DS1844(int address);
void write(int pot, int value);
int read(int pot);
DS1844(int16_t address);
void write(int16_t pot, int16_t value);
int16_t read(int16_t pot);
//private:
//int _address;
};
15 changes: 9 additions & 6 deletions examples/DS1844_example/DS1844_example.ino
Original file line number Diff line number Diff line change
@@ -23,9 +23,9 @@
#include <DS1844.h>
#include <Wire.h>

int brightness[4]; //This creates a 4 element array for the brightness values of the 4 LEDS
int readout; //This is the DS1844's returned value
const int address = 0x28; //This is the address of the DS1844 chip with all three address pins grounded.
int16_t brightness[4]; //This creates a 4 element array for the brightness values of the 4 LEDS
int16_t readout; //This is the DS1844's returned value
const int16_t address = 0x28; //This is the address of the DS1844 chip with all three address pins grounded.

/*
Addresses for common configurations of address pins:
@@ -41,18 +41,21 @@ DS1844 ds1844(address);
void setup() {
//Start serial communication
Serial.begin(9600);
Wire.begin();
}

void loop() {

//Increment through the potentiometers
for (int i = 0; i <= 3; i++) {
for (int16_t i = 0; i <= 3; i++) {
//NOTE: DS1844 RANGE IS 0-63 (6 bit integer)
while (brightness[i] <63) {
brightness[i]++; //Increment brightness
ds1844.write(i, brightness[i]); //Write the brightness to the selected potentiometer
readout = ds1844.read(i); //Display the newly written value to the serial monitor
Serial.println(readout);
Serial.print((readout >> 6), DEC); //prints potentiometer number (0-3)
Serial.print(",");
Serial.println(readout & (0x3F)); //prints potentiometer setting (0-63)
delay(50);
}
}
@@ -61,7 +64,7 @@ void loop() {
delay(1000);

//Turn all pots back to zero
for (int i = 0; i <= 3; i++) {
for (int16_t i = 0; i <= 3; i++) {
ds1844.write(i, 0);
brightness[i] = 0;
}