Sketch requires read 10 samples from Channel 1 and Channel 2 from ADC. Average the sample. Calculate a value based on the sample. Serial print the values. Here is what I have..not working.
#include <MCP3008.h>
// define pin connections
#define CS_PIN 12
#define CLOCK_PIN 9
#define MOSI_PIN 11
#define MISO_PIN 10
// put pins inside MCP3008 constructor
MCP3008 adc(CLOCK_PIN, MOSI_PIN, MISO_PIN, CS_PIN);
// ADC reference voltage / calibration value
#define V_REF 3.272
#define NUM_SAMPLES 10
int sum[2] = {0}; // sums of samples taken
unsigned char sample_count = 0; // current sample number
float voltage[2] = {0.0}; // calculated voltages
char l_cnt = 0; // used in 'for' loops
void setup() {
// open serial port
[login to view URL](9600);
}
void loop()
{
// take a number of analog samples and add them up
while (sample_count < NUM_SAMPLES) {
// sample each channel A1 to A2
for (l_cnt = 0; l_cnt < 2; l_cnt++) {
sum[l_cnt] += [login to view URL](A1 + l_cnt);
}
sample_count++;
delay(10);
}
// calculate the voltage for each channel
for (l_cnt = 0; l_cnt < 2; l_cnt++) {
voltage[l_cnt] = ((float)sum[l_cnt] / (float)NUM_SAMPLES * V_REF) / 1024.0;
}
[login to view URL](voltage[0] / (33 / 133));
[login to view URL]("\t");
// voltage 2 - B (pin A2)
[login to view URL](voltage[1] / (33 / 133));
[login to view URL]("\t");
// reset count and sums
sample_count = 0;
for (l_cnt = 0; l_cnt < 2; l_cnt++) {
sum[l_cnt] = 0;
}
[login to view URL]("");
}'
Hello.
I can fix that code today. I'll be online during the next 2 hours, or after 4-5 ours more.
Using of the TeamViewer will help to make that job faster, but it is not mandatory.
$25 USD trong 0 ngày
5,0 (21 nhận xét)
4,3
4,3
4 freelancer chào giá trung bình $20 USD cho công việc này
Hello, my name is Henrique, I graduated recently in electronic engineering and my conclusion project was done using the Arduino platform, I believe I have the necessary requirements to complete the project.