-
Notifications
You must be signed in to change notification settings - Fork 2
Code Documentation
- TFT_RST -1,TFT display shield
- TFT_CS 5, TFT display shield
- TFT_DC 6, TFT display shield
- DOUT 12, Load cells
- CLK 13, Load cells
- DOUT2 11, Load cells
- CLK2 9, Load cells
- LICKOMETER 18, Lick-o-meter
- BEEPER 19, Beeper
- SOLENOID 4, Solenoid
All functions can be called in the arduino script with the line: force.name();
- begin(): Initializes the pins, display, SD, neopixel, and load cells; Call in setup
- run(): Sense , UpdateDisplay, WriteToSD , SerialOutput; Call at least once per loop
- check_buttons(): reads buttons of ss, or the lcd display screen
- dateTime(uint16_t* date, uint16_t* time): return date or time using FAT_DATE and FAT_TIME macro to format fields
- graphLegend(): Displays the force output on F1 and F2 (the load cells) in grams, the force requirement in grams, the trial the FR/PR ratio, lick indication, the current number of successful presses, and the calibration status
- graphData(): Displays a properly scaled graph of x and y values based on outputValue and outputValue 2
- graphDateTime(): Displays month, day, hour, and minute
- UpdateDisplay(): Calls graphLegend(), graphData(), and graphDateTime()
- Sense(): The units of the measurement from the scale are converted into grams. If the applied force is great then required, pressLength is assigned to the current time and when the press began.
- Tare(): Resets scale every five seconds or when scale reading changes by more than 1,000 grams between the current and the last measurement
- Calibrate(): Increments the calibration value by either +0.1 g or -0.1 g, depending on whether the toggle is moved up or down
- CreateDataFile(): Initializes an SdFile, and if the Sd card is present, creates and names a file in the format F###_MMDDYYNN, where MM is month, DD is day, YY is year, and NN is an incrementing number for the number of files initialized each day. It opens the sD file, as logfile. A special error is thrown if the sD card isn’t present or cannot be initialized or if there is an error creating the SD logfile
- writeHeader(): Write data header to file of uSD; "MM:DD:YYYY hh:mm:ss, Seconds, Device_Number, ProgressiveRatio, Grams_req, Hold_time, Ratio, Dispense_amount, Dispense_delay, Timeout, Trials_per_block, Max_force, Trial, Lever1_Grams, Lever2_Grams, Licks"
- WriteToSD(): Prints date, time, device name, start time, ratio, required force, hold time, max_force, grams, grams2, all the relevant data ect… to logfile (the SD card). Throws an error if you can't access the logfile to write in.
- error(uint8_t errno): If any errors are detected with the SD card print on the screen
- getFilename(char *filename): This function creates a unique filename for each file that starts with "FRC", then the date in MMDDYY, then an incrementing number for each new file created on the same date
- logdata(): calls WriteToSD();
- Dispense(): Opens the solenoid for dispense_amount.
- Tone(): plays a 200 ms tone at 500 frequency
- Click(): plays a 8 ms tone at 800 frequency
- Timeout(int timeout_length): Functions so that there is a period of time (timeout_length) after liquid is successfully dispensed where the rodent cannot trigger another dispense; reset to full time if either lever is pushed
- SerialOutput(): Helpful with debugging, this function prints out the year, month, date, hour, minute, second, library version, trial number, and Force 1 and 2 on the load cells in grams.
- start_up_menu(): FORCE menu
- save_settings(): Save to settings.txt on SPI flash
- load_settings(): Load from settings.txt on SPI flash
- reset_settings(): resets variables to initial values (value on right →)
- print_settings(): Serial.prints the settings
not in FORCE library but required; useful in understanding cpp
- read_average(times): returns a long that is the average reading of the force cell
-
- Times: how many readings to do
- get_value(times): returns a double that is the current value of force on the cell without the tare weight; (read_average - OFFSET)
-
- OFFSET: the value that's subtracted from the actual reading (tare weight)
- get_units(time): returns a double that is get_value() divided by SCALE, that is the raw value divided by a value obtained via calibration; in our case SCALE is calibration
-
- Scale: value is used to convert the raw data to "human readable" data (measure units)
- tare(times): set the OFFSET value for tare weight
All variables can be modified in the arduino script with the line: force.name = appropriate value;
- Adafruit_miniTFTWing ss: Object to control the lcd display (the screen); stores state and functions for interacting with mini tft wing variant of seesaw helper IC**
- Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); Instantiate Adafruit ST7735 driver with selectable hardware SPI; cs = chip select pin number, dc = data command pin, rst - reset pin
- divideLine: int initialized to 57; for scaling the screen appropriately
- x_speed: int initialized to 1;
- x: int initialized to 0; For constructing proper graph display; increases by one while graphing to more position then reset to 0
- y: int uninitialized; The mapped value of outputValue from 0-750 to 0-57 (divideLine); scales outputValue to the screen
- lasty: int uninitialized; to store last y value
- y2: int uninitialized; to The mapped value of outputValue2 from 0-750 to 0-57 (divideLine); scales outputValue to the screen
- lasty2: int uninitialized; to store last y2 value
Load Cell 1
- Scale: HX711; The load cell 1 object
- calibration_factor: float initialized to -3300; this value is used to convert the raw data to "human readable" data (measure units)
- scaleChange: float initialized to 0; used to set sensitivity for delaying taring
- lastReading: float initialized to 0; used to store the previous outputValue
- outputValue: float, unitialized; This variable is set equal to value grams but remapped from one range to another (in this case 0-200 to 0-4095) ; a technique often used to read analog inputs. It is a conversion of grams.
- grams: float, unitialized; The return of the current value of force on load cell 1 divided by SCALE, that is the raw value divided by a value obtained via calibration
Load Cell 2
-
Scale2: HX711; The load cell 2 object
-
calibration_factor2: float initialized to -3300; this value is used to convert the raw data to "human readable" data (measure units)
-
scaleChange2: float initialized to 0; used to set sensitivity for delaying taring
-
lastReading2: float initialized to 0; used to store the previous outputValue2
-
outputValue2: float, unitialized; This variable is set equal to value grams2 but remapped from one range to another (in this case 0-200 to 0-4095) ; a technique often used to read analog inputs. It is a conversion of grams2.
-
grams2: float, unitialized; The return of the current value of force on load cell 1 divided by SCALE, that is the raw value divided by a value obtained via calibration
-
Calibrate_active: Boolean initialized to false;
-
calibrated: Boolean initialized to false;
- SD: SdFat;
- logfile: File, Create file object;
- filename[15]: Array of chars for file name data logged to named in setup;
- chipSelect: const int initialized to 10;
- dispense_time: float, initialized to 0; updated periodically to millis() when there's a successful lever press to operate the Timeout function
- dispense_amount: int, intialized to 20; Directly related to how long the solenoid is open; The value 110 will dispense one drop that hangs on sipper but does not fall.
- pressTime: unsigned long, initialized to 0; periodically set to millis() when any force is detected and used to calculated pressLength when grams > req
- pressLength: unsigned long, initialized 0; How long a successful press is held; 0 s if force < required ****``
- Dispense_delay: int, initialized to 4 s; Delay between successful press and liquid dispense; Can be changed during start up menu
- To successfully get a reward, the rodent must press with enough force, time, and
- FRC: int, initialized to 1; This is the unique # of the device; Can be changed during start up menu
- PR: Boolean initialized to false; If 0 then a fixed ratio, if 1 then a progressive ratio; Can be changed during start up menu
- timeout_length: int initialized to 10 s; Time in s after a successful dispense that another cannot be triggered, forces rodent to wait; It will reset if pressed; Can be changed during start up menu
- lick: Boolean initialized to false; set to true if mouse lick is detected
- start_timer: int initialized to 0; periodically set to millis() and used to evaluate timing of behaviors of the device
- trial: int initialized to 1; Increases by one when liquid successfully dispensed; Can be changed during start up menu
- presses: int initialized to 0; The number of successful presses the rodent has achieved;
- req: int initialized to 2 g; The force requirement that the mouse must reach on the lever; Can be changed during start up menu
- pressStart: unsigned long initialized to 0;
- ratio: int initialized to 1; all PR sessions will have the FR ratio of 1; Can be changed during start up menu
- hold_time: int initialized to 350 ms; Can be changed during start up menu
- trials_per_block: int initialized to 10; Can be changed during start up menu
- max_force: int initialized to 20 g; If the program calls for an increasing force req this is the max it will reach without resetting; Can be changed during start up menu
- start_time: unsigned long initialized to 0; periodically set to millis() to calculate how long the startup menu should be displayed before starting the session (set to 1- seconds)
- start_up: Boolean initialized to true; set to false after 10 seconds so menu disappears and the sesion begins
- settings[9]: array of ints for saving settings on QSPI flash;
- settings_recalled[9]: array of ints for reading from QSPI flash;