Skip to content

Commit 902e037

Browse files
committed
Added priming to run function
1 parent 66b66a6 commit 902e037

3 files changed

Lines changed: 17 additions & 21 deletions

File tree

examples/Bandit_Task/Bandit_Task.ino

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ int trial_counter = 0; // Tracks how many pellet
2727
int highp_counter = 0; // Tracks how many pokes in a row in high probability poke
2828
int trialTimeout = 5; //timeout duration after each poke, set to 0 to remove the timeout
2929
int probs[5] = {10, 30, 50, 70, 90};
30-
unsigned long trial_start = 0;
31-
unsigned long trial_length = 5000;
32-
bool trial_available = false;
3330
bool press = false;
3431

3532
void setup() {
@@ -65,19 +62,19 @@ void loop() {
6562
////////////////////////////////////////////////////////////////
6663
force.readPoke();
6764
if (force.poke) {
68-
force.run(true);
69-
trial_start = millis();
65+
force.run();
66+
force.trial_start = millis();
7067
force.Tone();
71-
trial_available = true;
68+
force.trial_available = true;
7269
}
7370

74-
while (((millis()-trial_start) < force.trial_window) && trial_available == true) {
71+
while (((millis()-force.trial_start) < force.trial_window) && force.trial_available) {
7572
force.ratioLeft = prob_left;
7673
force.ratioRight = prob_right;
7774
force.trials_per_block = trial_counter;
7875
force.FRC = highp_counter;
7976
force.library_version = trialsToSwitch;
80-
force.run(true);
77+
force.run();
8178

8279
/////////////////////////////////////////////////////////////
8380
//// If mouse presses the left lever ///
@@ -90,15 +87,14 @@ void loop() {
9087
highp_counter = 0;
9188
}
9289
if (random(100) < prob_left) {
93-
force.Tone();
9490
force.DispenseLeft();
9591
trial_counter ++;
9692
}
9793
else {
9894
force.Tone(300,600);
9995
}
10096
press = true;
101-
trial_available = false;
97+
force.trial_available = false;
10298
}
10399

104100
//////////////////////////////////////////////////////////////
@@ -112,31 +108,31 @@ void loop() {
112108
highp_counter = 0;
113109
}
114110
if (random(100) < prob_right) {
115-
force.Tone();
116111
force.DispenseRight();
117112
trial_counter ++;
118113
}
119114
else {
120115
force.Tone(300,600);
121116
}
122117
press = true;
123-
trial_available = false;
118+
force.trial_available = false;
124119
}
125120
}
126121

127122
//////////////////////////////////////////////////////////////
128123
//// If there was no press during the time window ////
129124
/////////////////////////////////////////////////////////////
130-
if (trial_available && press == false) {
125+
if (force.trial_available && press == false) {
131126
force.Tone(300,600);
127+
force.trial_available = false;
132128
}
133129

134130
//////////////////////////////////////////////////////////////
135131
//// Finish trial and start inter-trial timeout ////
136132
/////////////////////////////////////////////////////////////
137133
if (press) {
138134
press = false;
139-
trial_available = false;
135+
force.trial_available = false;
140136
force.Timeout(trialTimeout);
141137
}
142138

src/Force.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ void Force::begin() {
961961

962962

963963
////////////////////////////////////////////////////
964-
//Run function to updates things on every loop//////
964+
//t function to updates things on every loop//////
965965
////////////////////////////////////////////////////
966966
void Force::run(bool log_data) {
967967
SenseLeft();
@@ -1095,8 +1095,8 @@ void Force::graphLegend() {
10951095
tft.print(ratioLeft);
10961096

10971097
//Print remaining trial window
1098-
if ((trial_length < trial_window) && (trial_length != 0)) {
1099-
tft.setCursor(45,30);
1098+
if (trial_available) {
1099+
tft.setCursor(60,50);
11001100
tft.setTextColor(ST7735_WHITE);
11011101
tft.print("Trial Available");
11021102
//tft.print((trial_window - trial_length)/1000, 3);
@@ -1375,7 +1375,7 @@ void Force::Click() {
13751375
void Force::DispenseLeft() {
13761376
dispensing = true;
13771377
trialLeft++;
1378-
Tone();
1378+
Tone(4000,200);
13791379
float successTime = millis();
13801380
while ((millis() - successTime) < (dispense_delay * 1000)){
13811381
tft.setCursor(85, 44);
@@ -1413,7 +1413,7 @@ void Force::DispenseLeft() {
14131413
void Force::DispenseRight() {
14141414
dispensing = true;
14151415
trialRight++;
1416-
Tone();
1416+
Tone(4000,200);
14171417
float successTime = millis();
14181418
while ((millis() - successTime) < (dispense_delay * 1000)){
14191419
tft.setCursor(85, 44);
@@ -1535,7 +1535,7 @@ void Force::prime_dispense() {
15351535
//// Check last dispense ////
15361536
//////////////////////////////////
15371537
void Force::check_lastDispense() {
1538-
if ((millis() - last_dispense) > 60*1000) {
1538+
if ((millis() - last_dispense) > 300*1000) {
15391539
last_dispense = millis();
15401540
prime_dispense();
15411541
}

src/Force.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Force {
5555

5656
// --- Basic functions --- //
5757
void begin();
58-
void run(bool log_data = false);
58+
void run(bool log_data = true);
5959
void check_buttons();
6060
void readPoke();
6161

0 commit comments

Comments
 (0)