forked from tardate/LittleArduinoProjects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNOR.ino
62 lines (45 loc) · 1.58 KB
/
NOR.ino
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
/*
ResistorTransistorLogic/NOR
Test the basic resistor-transistor logic NOR gate
For info and circuit diagrams see https://github.com/tardate/LittleArduinoProjects/tree/master/Electronics101/ResistorTransistorLogic/NOR
*/
#define IN_A_PIN 6
#define IN_B_PIN 7
#define STEP_DELAY 500
#include <FlexiTimer2.h> // use timer for sampling to get even time base for data
#define TRACE_COUNT 3 // 1,2,..6 - the number of values to sample from analog inputs A0,1,..5 respectively
#define INPUT1_PIN A0 // the first analog input.
#define SAMPLING_FREQUENCY 10 // milliseconds
void setup() {
pinMode(IN_A_PIN, OUTPUT);
pinMode(IN_B_PIN, OUTPUT);
Serial.begin(115200); // initialize serial communications (to match that used by PlotNValues.pde)
FlexiTimer2::set(SAMPLING_FREQUENCY, sample); // set sampling procedure on timer interrupt
FlexiTimer2::start();
}
void loop() {
digitalWrite(IN_A_PIN, LOW);
digitalWrite(IN_B_PIN, LOW);
delay(STEP_DELAY);
digitalWrite(IN_A_PIN, LOW);
digitalWrite(IN_B_PIN, HIGH);
delay(STEP_DELAY);
digitalWrite(IN_A_PIN, HIGH);
digitalWrite(IN_B_PIN, LOW);
delay(STEP_DELAY);
digitalWrite(IN_A_PIN, HIGH);
digitalWrite(IN_B_PIN, HIGH);
delay(STEP_DELAY);
}
/*
Command: read the current values and send to the serial port.
This sends raw values (0-1023) because that is what PlotNValues processing script expects.
*/
void sample() {
String result = "";
for(int i=0; i < TRACE_COUNT; i++) {
if(i>0) result += ",";
result += analogRead(INPUT1_PIN + i);
}
Serial.println(result);
}