-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Photodiode array library first edition!
- Loading branch information
Showing
4 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "ADCSPhotodiodeArray.h" | ||
|
||
/* | ||
* Configure the pins attached to the multiplexer (a-c) as outputs and the pin on analog input as an input. | ||
*/ | ||
ADCSPhotodiodeArray::ADCSPhotodiodeArray(uint8_t analog_input, uint8_t a, uint8_t b, uint8_t c){ | ||
// configure digital pins | ||
pinMode(a, OUTPUT); | ||
digitalWrite(a, LOW); | ||
|
||
pinMode(b, OUTPUT); | ||
digitalWrite(b, LOW); | ||
|
||
pinMode(c, OUTPUT); | ||
digitalWrite(c, LOW); | ||
|
||
// configure analog pins | ||
pinMode(analog_input, INPUT); | ||
} | ||
|
||
/* | ||
* Read the value measured on one of the 6 multiplexer channels. | ||
*/ | ||
int ADCSPhotodiodeArray::read(uint8_t channel){ | ||
switch(channel){ | ||
case 0: | ||
digitalWrite(a, LOW); | ||
digitalWrite(b, LOW); | ||
digitalWrite(c, LOW); | ||
break; | ||
|
||
case 1: | ||
digitalWrite(a, HIGH); | ||
digitalWrite(b, LOW); | ||
digitalWrite(c, LOW); | ||
break; | ||
|
||
case 2: | ||
digitalWrite(a, LOW); | ||
digitalWrite(b, HIGH); | ||
digitalWrite(c, LOW); | ||
break; | ||
|
||
case 3: | ||
digitalWrite(a, HIGH); | ||
digitalWrite(b, HIGH); | ||
digitalWrite(c, LOW); | ||
break; | ||
|
||
case 4: | ||
digitalWrite(a, LOW); | ||
digitalWrite(b, LOW); | ||
digitalWrite(c, HIGH); | ||
break; | ||
|
||
case 5: | ||
digitalWrite(a, LOW); | ||
digitalWrite(b, LOW); | ||
digitalWrite(c, HIGH); | ||
break; | ||
|
||
default: | ||
digitalWrite(a, LOW); | ||
digitalWrite(b, LOW); | ||
digitalWrite(c, LOW); | ||
|
||
} | ||
|
||
return analogRead(analog_pin); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef ADCSPHOTODIODEARRAY_H | ||
#define ADCSPHOTODIODEARRAY_H | ||
|
||
#include <Arduino.h> | ||
|
||
/* | ||
* Truth table for the multiplexer that the 6 photodiodes will be hooked up to. | ||
* | ||
* INPUTS | ||
* | A | B | C | CHANNEL | | ||
* ----------------------- | ||
* | L | L | L | 0 | | ||
* | H | L | L | 1 | | ||
* | L | H | L | 2 | | ||
* | H | H | L | 3 | | ||
* | L | L | H | 4 | | ||
* | H | L | H | 5 | | ||
* | ||
*/ | ||
|
||
class ADCSPhotodiodeArray { | ||
private: | ||
uint8_t analog_pin, a, b, c; | ||
|
||
public: | ||
ADCSPhotodiodeArray(uint8_t analog_input, uint8_t a, uint8_t b, uint8_t c); | ||
int read(uint8_t channel); // select which channel to read from by number | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters