-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNanoject.ino
199 lines (185 loc) · 4.49 KB
/
Nanoject.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Trial to make a directory structure and interface with keys
#include <LiquidCrystal.h>
#include <Wire.h>
#include <EEPROM.h>
/*************************************************************
The nanoject needs some form of menu stucture:
*************************************************************/
// Select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// Define our special characters for the rotating circle
byte p20[8] = {
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
};
byte p40[8] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
};
byte p60[8] = {
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
};
byte p80[8] = {
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
};
byte p100[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
byte downArrow[8] = {
0b00100, // *
0b00100, // *
0b00100, // *
0b00100, // *
0b00100, // *
0b10101, // * * *
0b01110, // ***
0b00100 // *
};
byte upArrow[8] = {
0b00100, // *
0b01110, // ***
0b10101, // * * *
0b00100, // *
0b00100, // *
0b00100, // *
0b00100, // *
0b00100 // *
};
byte menuCursor[8] = {
B01000, // *
B00100, // *
B00010, // *
B00001, // *
B00010, // *
B00100, // *
B01000, // *
B00000 //
};
// Set up the menu:
String menuItems[] = {"Set Volume", "Set Time", "Inject!", "Manual Move", "Calibrate","Position"};//, "Move UP", "Move DOWN"};
// Define some variables that we need:
// Navigation button variables
int readKey;
int savedDistance = 0;
// Menu control variables
int menuPage = 0;
int maxMenuPages = round(((sizeof(menuItems) / sizeof(String)) / 2) + .5);
int cursorPosition = 0;
// Characters
int wheel = 0;
// For injections:
int Volume;
int Time;
int VolumeIncr;
int TimeIncr;
int MotorPosition = 0; // 0 is fully retracted, we have a limited number of steps in total.
int MaxMotorPosition = 3000; // We don't want to jam the nanoject, so a maximal position is wise.
// For calibrations:
float Diameter = 0;
int CalibrationSteps[] = {1, 5, 10, 25, 50, 100, 250, 500};
float CalibrationDiameters[] = {0, 0, 0, 0, 0, 0, 0, 0};
float CalibrationVolumes[] = {0, 0, 0, 0, 0, 0, 0, 0};
int NrCalibrationSteps = 6;
float sum_xy = 0;
float sum_xx = 0;
float avgVolumes = 0;
float Rres = 0;
float Rtot = 0;
float Rsquare = 0;
float CalibrationSlope;
int BinaryCharacterArray[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int BinaryDecimalArray[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int BinaryArray[8];
int choice = 0; // Should be zero, because default zero
// For the motor:
int pwm_a = 3; //PWM control for motor outputs 1 and 2
int pwm_b = 11; //PWM control for motor outputs 3 and 4
int dir_a = 2; //direction control for motor outputs 1 and 2
int dir_b = 12; //direction control for motor outputs 3 and 4
int pwm_a_val;
int pwm_b_val;
int dir_a_val;
int dir_b_val;
int revs = 0;
int wait = 50;
void setup()
{
Serial.begin(9600);
// First we set some pins and parameters for the stepper motor:
pinMode(pwm_a, OUTPUT); //Set control pins to be outputs
pinMode(pwm_b, OUTPUT);
pinMode(dir_a, OUTPUT);
pinMode(dir_b, OUTPUT);
pwm_a_val = digitalRead(pwm_a);
pwm_b_val = digitalRead(pwm_b);
dir_a_val = digitalRead(dir_a);
dir_b_val = digitalRead(dir_b);
// Starting the LCD:
lcd.begin(16, 2); // start the lcd library
// Special Characters:
lcd.createChar(0, menuCursor);
lcd.createChar(1, upArrow);
lcd.createChar(2, downArrow);
lcd.createChar(3, p20);
lcd.createChar(4, p40);
lcd.createChar(5, p60);
lcd.createChar(6, p80);
lcd.createChar(7, p100);
// Following values are for the injection, they are saved in EEPRMOM!
// EERPROM can hold values up to 255, so we need a trick:
int EEPROMVolume = EEPROM.read(0);
int EEPROMTime = EEPROM.read(1);
// Get the correct volume and time:
if (EEPROMVolume<=10) Volume = EEPROMVolume*5;
else if (EEPROMVolume<=30) Volume = EEPROMVolume*10-50;
else Volume = EEPROMVolume*50-1250;
if (Volume>1000) Volume = 1000;
if (EEPROMTime<=10) Time = EEPROMTime*5;
else if (EEPROMTime<=30) Time = EEPROMTime*10-50;
else Time = EEPROMTime*50-1250;
if (Time>1200) Time = 1200;
// Get the calibration from memory:
CalibrationSlope = Load();
Serial.println(CalibrationSlope);
// Welcome message
lcd.setCursor(3,0);
lcd.print("WELCOME TO");
lcd.setCursor(0,1);
lcd.print("ARDUINO NANOJECT");
delay(1000);
lcd.clear();
};
void loop()
{
mainMenuDraw();
drawCursor();
operateMainMenu();
};