/
microscope-controller.ino
84 lines (67 loc) · 1.7 KB
/
microscope-controller.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <FastLED.h>
#define NUM_LEDS 12
#define DATA_PIN 9
const int dirPin = 2;
const int stepPin = 3;
const int steps = 1600;
int stepDelay;
int mode = 2; // 0: stepper control, 1: stepper adjustment, 2: menu
int step_interval = 10;
CRGB leds[NUM_LEDS];
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds,NUM_LEDS);
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
Serial.begin(9600);
FastLED.setCorrection(TypicalPixelString);
FastLED.setTemperature(CoolWhiteFluorescent);
FastLED.setBrightness(255);
}
void loop() {
// put your main code here, to run repeatedly:
leds[0] = CRGB::White;
leds[1] = CRGB::White;
leds[2] = CRGB::White;
leds[3] = CRGB::White;
leds[4] = CRGB::White;
leds[5] = CRGB::White;
leds[6] = CRGB::White;
leds[7] = CRGB::White;
leds[8] = CRGB::White;
leds[9] = CRGB::White;
leds[10] = CRGB::White;
leds[11] = CRGB::White;
FastLED.show();
control();
}
void control(){
if(Serial.available()){
stepDelay = 250;
char val = Serial.read();
if(val == 'U'){
digitalWrite(dirPin,HIGH);
for(int x=0; x<step_interval; x++){
digitalWrite(stepPin,HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin,LOW);
delayMicroseconds(stepDelay);
}
}
else if(val == 'D'){
digitalWrite(dirPin,LOW);
for(int x=0;x<step_interval;x++){
digitalWrite(stepPin,HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin,LOW);
delayMicroseconds(stepDelay);
}
}
else if(val == 'L'){
step_interval = 100;
}
else if(val == 'S'){
step_interval = 10;
}
}
}