forked from practicalarduino/ScopeAnalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScopeAnalog.pde
68 lines (61 loc) · 1.44 KB
/
ScopeAnalog.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* ScopeAnalog
*
*
* Copyright 2009 Jonathan Oxer <[email protected]>
* Copyright 2009 Hugh Blemings <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. http://www.gnu.org/licenses/
*
* www.practicalarduino.com/projects/scope-logic-analyzer
*/
/**
* Define macros for setting and clearing bits in the ADC prescale register
*/
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
int val;
/**
* Sets the ADC prescaler to 16, prepares the relevant digital inputs,
* and opens serial comms with the host
*/
void setup()
{
sbi(ADCSRA,ADPS2);
cbi(ADCSRA,ADPS1);
cbi(ADCSRA,ADPS0);
pinMode(6, INPUT);
pinMode(7, INPUT);
Serial.begin(115200);
}
/**
* Read the inputs and send values to the host. The analog read values
* from the digital inputs need to be fudged so they read 0 or 1023
*/
void loop()
{
for( int i=0; i<6; i++ ){
Serial.print( analogRead(i) );
Serial.print(" ");
}
if( digitalRead(6) == 1){
Serial.print(1023);
Serial.print(' ');
} else {
Serial.print(0);
Serial.print(' ');
}
if( digitalRead(7) == 1){
Serial.print(1023);
} else {
Serial.print(0);
}
Serial.println();
}