Skip to content

Commit e193696

Browse files
committed
v1.2.0
1 parent b53c455 commit e193696

5 files changed

Lines changed: 90 additions & 14 deletions

File tree

.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
some-text

examples/FORCE/FORCE.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// DON'T EDIT THESE LINES
1818
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1919
#include <Force.h> //Include FORCE library
20-
String ver = "v1.1.2"; //unique identifier text
20+
String ver = "v1.2.0"; //unique identifier text
2121
Force force(ver); //start FORCE object
2222

2323
void setup() {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
FORCE example code
3+
by Lex Kravitz and Bridget Matikainen-Ankney
4+
5+
alexxai@wustl.edu
6+
May, 2021
7+
8+
KravitzLabDevices/FORCE_library is licensed under the GNU General Public License v3.0
9+
10+
Permissions of this strong copyleft license are conditioned on making available complete source code of licensed works
11+
and modifications, which include larger works using a licensed work, under the same license. Copyright and license
12+
notices must be preserved. Contributors provide an express grant of patent rights.
13+
14+
*/
15+
16+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
17+
// DON'T EDIT THESE LINES
18+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19+
#include <Force.h> //Include FORCE library
20+
String ver = "v1.2.0"; //unique identifier text
21+
Force force(ver); //start FORCE object
22+
23+
void setup() {
24+
force.begin(); //setup FORCE
25+
}
26+
27+
void loop() {
28+
force.run(); //call force.run() at least once per loop
29+
30+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
31+
// WRITE CUSTOM BEHAVIORAL CODE BELOW HERE
32+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
33+
if (force.pressLength > force.hold_time) { //if the force lever is held down for longer than the hold_req
34+
//Choose a random number
35+
randomSeed(millis()); //get a new randomSeed here so the sequence isn't the same every time
36+
int randnum = random(1, 4); //Pick a random number between 1 and 3
37+
Serial.print("Random Num: "); //Print the random number
38+
Serial.println(randnum);
39+
40+
force.presses++; //keep count of successful presses
41+
force.Dispense(); //dispense reward
42+
43+
if (randnum == 3) { //if random number is 3...
44+
while ((force.unixtime - force.dispenseTime) < 15) { //...and it is within 15 seconds of a dispense
45+
force.run(); //keep force screen and timers running while waiting around for the 15sec delay
46+
if (force.lick == true) { //if animal licks in this time period:
47+
48+
/////////////////////////////////////////////////
49+
// FORCE does this when both conditions are true
50+
/////////////////////////////////////////////////
51+
Serial.println("Output triggered!");
52+
digitalWrite (13, HIGH);
53+
delay(1000);
54+
digitalWrite (13, LOW);
55+
56+
break;
57+
}
58+
}
59+
}
60+
61+
force.Timeout(force.timeout_length); //timeout (length in seconds)
62+
}
63+
}

src/Force.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,30 @@ Force::Force(String ver) {
1414
library_version = ver;
1515
}
1616

17+
/////////////////////////////////////////////////////////////////////////
18+
// RTC Functions
19+
/////////////////////////////////////////////////////////////////////////
20+
RTC_PCF8523 rtc;
21+
22+
void dateTime(uint16_t* date, uint16_t* time) {
23+
DateTime now = rtc.now();
24+
// return date using FAT_DATE macro to format fields
25+
*date = FAT_DATE(now.year(), now.month(), now.day());
26+
27+
// return time using FAT_TIME macro to format fields
28+
*time = FAT_TIME(now.hour(), now.minute(), now.second());
29+
}
30+
1731
/////////////////////////////////////////////////////////////////////////
1832
//
1933
/////////////////////////////////////////////////////////////////////////
2034
void Force::run() {
2135
Sense();
2236
UpdateDisplay();
2337
WriteToSD();
24-
SerialOutput();
38+
DateTime now = rtc.now();
39+
unixtime = now.unixtime();
40+
// SerialOutput();
2541
}
2642

2743
/////////////////////////////////////////////////////////////////////////
@@ -49,6 +65,8 @@ void Force::Dispense() {
4965
digitalWrite(13, HIGH); // RED LED
5066
delay (dispense_amount); //how long to open solenoid?
5167
digitalWrite(SOLENOID, LOW);
68+
DateTime now = rtc.now();
69+
dispenseTime = now.unixtime();
5270
digitalWrite(A2, LOW);
5371
digitalWrite(13, LOW); // RED LED
5472
pressTime = millis();
@@ -85,19 +103,7 @@ void Force::Click() {
85103
tone(A5, 800, 8);
86104
}
87105

88-
/////////////////////////////////////////////////////////////////////////
89-
// RTC Functions
90-
/////////////////////////////////////////////////////////////////////////
91-
RTC_PCF8523 rtc;
92-
93-
void dateTime(uint16_t* date, uint16_t* time) {
94-
DateTime now = rtc.now();
95-
// return date using FAT_DATE macro to format fields
96-
*date = FAT_DATE(now.year(), now.month(), now.day());
97106

98-
// return time using FAT_TIME macro to format fields
99-
*time = FAT_TIME(now.hour(), now.minute(), now.second());
100-
}
101107

102108
/////////////////////////////////////////////////////////////////////////
103109
// Begin
@@ -469,6 +475,8 @@ void Force::graphLegend() {
469475
tft.setTextColor(ST7735_WHITE);
470476
tft.setCursor(0, 28);
471477
tft.print ("Lick");
478+
DateTime now = rtc.now();
479+
lickTime = now.unixtime();
472480
}
473481

474482
if (calibrated == false){

src/Force.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class Force {
9797
void error(uint8_t errno);
9898
void getFilename(char *filename);
9999
void logdata();
100+
unsigned long unixtime = 0;
101+
100102

101103
// --- Solenoid functions --- //
102104
float dispense_time = 0;
@@ -126,6 +128,8 @@ class Force {
126128
int trials_per_block = 10;
127129
int max_force = 20;
128130
unsigned long start_time = 0;
131+
unsigned long lickTime = 0;
132+
unsigned long dispenseTime = 0;
129133

130134
// --- Serial out--- //
131135
void SerialOutput();

0 commit comments

Comments
 (0)