From 0b237312c1ff5543b4cdd41c624a973cc3ef86bb Mon Sep 17 00:00:00 2001 From: ghazal-ashrafi <54713538+ghazal-ashrafi@users.noreply.github.com> Date: Fri, 30 Aug 2019 09:39:48 -0400 Subject: [PATCH 01/12] Update Arduino_stim_1-1.ino Removed for loop --- Arduino_stim_1-1/Arduino_stim_1-1.ino | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Arduino_stim_1-1/Arduino_stim_1-1.ino b/Arduino_stim_1-1/Arduino_stim_1-1.ino index a93b32f..2056e68 100644 --- a/Arduino_stim_1-1/Arduino_stim_1-1.ino +++ b/Arduino_stim_1-1/Arduino_stim_1-1.ino @@ -52,9 +52,7 @@ void loop() { switch(cam){ // Switch between high and low states case HIGH: // Indicates Frame is being read if(digitalRead(ins[1]) == HIGH || in == 1){ // If either 1 input or the external shutter is open - for(int i=1; i < out; i++){ // Loop over laser outputs - digitalWrite(outs[i],HIGH); // write outputs to high - } + } count++; // increment counting variable if(count == stim){ // If frame number equals stimulation number @@ -100,4 +98,3 @@ void loop() { } } // end serial loop } // end main loop - From e63f564f8ba68df34a1a5c63ca2048895e26ff03 Mon Sep 17 00:00:00 2001 From: ghazal-ashrafi <54713538+ghazal-ashrafi@users.noreply.github.com> Date: Fri, 30 Aug 2019 09:40:25 -0400 Subject: [PATCH 02/12] Update Arduino_stim_1-1.ino --- Arduino_stim_1-1/Arduino_stim_1-1.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Arduino_stim_1-1/Arduino_stim_1-1.ino b/Arduino_stim_1-1/Arduino_stim_1-1.ino index 2056e68..100a3d2 100644 --- a/Arduino_stim_1-1/Arduino_stim_1-1.ino +++ b/Arduino_stim_1-1/Arduino_stim_1-1.ino @@ -52,7 +52,9 @@ void loop() { switch(cam){ // Switch between high and low states case HIGH: // Indicates Frame is being read if(digitalRead(ins[1]) == HIGH || in == 1){ // If either 1 input or the external shutter is open - + for(int i=1; i < out; i++){ // Loop over laser outputs + digitalWrite(outs[i],HIGH); // write outputs to high + } } count++; // increment counting variable if(count == stim){ // If frame number equals stimulation number From 6566b2f5b18b585614faf1f2222fc96d329427dc Mon Sep 17 00:00:00 2001 From: Andrew Nelson <33523882+ajn2004@users.noreply.github.com> Date: Tue, 17 Sep 2019 07:34:18 -0400 Subject: [PATCH 03/12] Update Arduino_stim_1-3.ino --- Arduino_stim_1-3/Arduino_stim_1-3.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Arduino_stim_1-3/Arduino_stim_1-3.ino b/Arduino_stim_1-3/Arduino_stim_1-3.ino index 03f8664..a69becc 100644 --- a/Arduino_stim_1-3/Arduino_stim_1-3.ino +++ b/Arduino_stim_1-3/Arduino_stim_1-3.ino @@ -21,13 +21,13 @@ // 1.2 Added switcher support as a switch statement AJN 9-29-19 // USer Variables -int in = 2; // Specify number of inputs used -int out = 3; //Specify number of outputs used +int in = 1; // Specify number of inputs used +int out = 4; //Specify number of outputs used int ins[] = {13, 12}; // {Camera, Ext. Shut} -int outs[] = {5, 4, 3}; // {Stimulate, Laser1, Laser2, ...} +int outs[] = {7, 2, 3, 4}; // {Stimulate, Laser1, Laser2, ...} int f = 1; // initial frequency of Stimulation in Hz int N = 10; // Number of stimuli -unsigned long pwidth = 1; // pulse width in milliseconds +long pwidth = 1; // pulse width in milliseconds // Initialization of user independent variables. unsigned int count = 0; // Initialize Frame number (no negative frames) @@ -71,6 +71,7 @@ void loop() { int cmd = 0; // Command variable for updating arduino state through USB cam = digitalRead(ins[0]); // Read camera state for this frame if(cam0 != cam) { // If camera state has changed execute following + cmd = count + 5; switch(cam){ // Switch between high and low states case HIGH: // Indicates Frame is being read if(digitalRead(ins[1]) == HIGH || in == 1){ // If either 1 input or the external shutter is open @@ -197,4 +198,3 @@ void train(){ // run a stimulation train at known intervals delay(p); // delay by period and repeat } } - From 76ac0cac654021d58903d9f1d56b0502cc809baf Mon Sep 17 00:00:00 2001 From: Andrew Nelson <33523882+ajn2004@users.noreply.github.com> Date: Mon, 30 Sep 2019 14:46:58 -0400 Subject: [PATCH 04/12] Create Arduino_stim_2-1.ino --- Arduino_stim_2-1/Arduino_stim_2-1.ino | 193 ++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 Arduino_stim_2-1/Arduino_stim_2-1.ino diff --git a/Arduino_stim_2-1/Arduino_stim_2-1.ino b/Arduino_stim_2-1/Arduino_stim_2-1.ino new file mode 100644 index 0000000..0d61a6c --- /dev/null +++ b/Arduino_stim_2-1/Arduino_stim_2-1.ino @@ -0,0 +1,193 @@ +// Arduino Stim v 1.3 +// +// This is an arduino sketch attempting to handle the electrical communication between +// an EMCCD, Isolator Battery, Coherent Laser box, in a controlled and programable fashion. +// This version is a working version that will drive up to a number of digital outputs. +// It operates by reading the rising edge of camera frame. When the camera frame is high, +// the digital signal for lasers goes high, then turn off with the camera fire line. The +// Stimulator turns on for a specified frame. +// AN 8-29-2019 Tim Ryan Lab +// +// User commands while running +// 'r' reset counting +// 's#' set frame # to new stimulation value +// 'S' stimulate train immediately +// 'f#' set frequency of train +// 'N#' set number of stimulations / train +// 'p' +// +// Change_log +// 2.1 Fully functional arduino program, incorporating arming protocol and streamlining communication +// 1.3 Added function generator support AJN 9-29-19 +// 1.2 Added switcher support as a switch statement AJN 9-29-19 + +// USer Variables +int in = 1; // Specify number of inputs used +int out = 4; //Specify number of outputs used +int ins[] = {13, 12}; // {Camera, Ext. Shut} +int outs[] = {7, 2, 3, 4}; // {Stimulate, Laser1, Laser2, ...} +int f = 1; // initial frequency of Stimulation in Hz +int N = 10; // Number of stimuli +long pwidth = 1; // pulse width in milliseconds + +// Initialization of user independent variables. +unsigned int count = 0; // Initialize Frame number (no negative frames) +bool cam0 = LOW; // Initialize 'previous' camera state as low +bool cam = LOW; // Initialize 'current' state as high +int arm = 0; +int stim = 10; // Initialize no stimulation unless asked for it (setting to -1 prevents stimulation) +int laser_state = 0; // laser state to induce switching +long lastmil = 0; // Storage variable for previous time + +unsigned long p = 1000/f; // Period between stimuli in ms +int flag = 0; // flag for timing + +int n = 0; // stimulus counting variable + + + +void setup() { + for (int i =0; i< in; i++){ // loop over inputs + pinMode(ins[i],INPUT); // activate inputs + } + for (int i =0; i< out; i++){ // activate outputs + pinMode(outs[i],OUTPUT); + digitalWrite(outs[i], LOW); // initialize outputs to low + } + + // This section is for USB communication early on and will be streamlined after debugging 8-29-19 + Serial.begin(9600); + Serial.setTimeout(100); // we won't be communicating that much, 100 ms should be fine + Serial.print("Stimulus set to frame "); + Serial.print(stim); + Serial.print("\n"); + +} + +void loop() { + + unsigned long nowt = millis(); + int cmd = 0; // Command variable for updating arduino state through USB + cam = digitalRead(ins[0]); // Read camera state for this frame + if(cam0 != cam) { // If camera state has changed execute following + cmd = count + 5; + switch(cam){ // Switch between high and low states + case HIGH: // Indicates Frame is being read + if(digitalRead(ins[1]) == HIGH || in == 1){ // If either 1 input or the external shutter is open + switch(laser_state){ + case 0: // all on or off + for(int i=1; i < out; i++){ // Loop over laser outputs + digitalWrite(outs[i],HIGH); // write outputs to high + } + case 1: //switcher between laser1 and laser2 + switch(count%2){ + case 0: + digitalWrite(outs[3],HIGH); + break; + case 1: + digitalWrite(outs[1],HIGH); + break; + }//end switch las_stat for switcher + } // end switch laser state + + count++; // increment counting variable + if(count == stim){ + if(arm == 1){flag = 1;} + } + Serial.print(count); // print camera frame + Serial.print("\n"); // newline character + } + break; // Don't execute any more of the switch loop + + case LOW: // Indicates the frame has finished aquistion + for(int i=1; i < out; i++){ // turn off lasers + digitalWrite(outs[i],LOW); // write pin low + } // all other work is taken care of on the rising edge. However if there is a use for the falling edge it would go here + break; + } + } // end state change section + cam0 = cam; // update previous state to current state + + // Stimulation Section + if(flag == 1){ // if stimulation flag is high, look for stimulation behavior + if(n == 0){ // if no stimuli have been given + stimulate(); // stimulate + //Serial.print(n); + lastmil = nowt; // update time + n = n+1; // increment stim count + } + + else{ // if one stimulus has already been given, wait p amount of milliseconds + if(nowt - lastmil >= p && n0){ // if there is a usb input, execute following + cmd = Serial.read(); // Read the 1 byte input + Serial.print("Confirmed "); // Respond to USB + switch(cmd){ // switch statement allows for building of a variety of command interfaces + case 114: // if the incoming byte is 'r' + count = 0; // reset the counting variable to 0 + Serial.print("count = 0\n"); // Confirm change + break; + case 115: // If incoming byte is 's' the following bytes will be a framenumber + stim = Serial.parseInt(); // parse the bytes into integers + Serial.print("stimulus is now on frame "); // Confirm input + Serial.print(stim); // Repeat input for confirmation + Serial.print("\n"); // newline + break; + case 97: // If incoming byte is 's' the following bytes will be a framenumber + arm = (arm +1) % 2; + Serial.print("Arm is now "); // Confirm input + Serial.print(arm); // Repeat input for confirmation + Serial.print("\n"); // newline + break; + case 83: // If the incoming bit is 'S' then stimulate now + train(); // Run a train of stimuli at p intervals + Serial.print("STIM!\n"); // communicate sitmulation + break; + case 119: // If the incoming bit is 'w' then turn on/off switcher + if(laser_state == 1){laser_state = 0;} + else if(laser_state == 0 ){laser_state = 1;} + Serial.print("Switcher Toggled\n"); // Issue confirmation + break; + case 102: // if incoming bit is 'f' reset frequency + f = Serial.parseInt(); // parse the bytes into integers + p = 1000/f; // recalculate period + Serial.print("stimulus is now at "); // Confirm Input + Serial.print(f); // Repeat input for confirmation + Serial.print("Hz\n"); // newline + break; + case 78: // if incoming bit is 'N' change number of stimuli + N =Serial.parseInt(); // Parse incoming integer into N + Serial.print("Number of stimuli is not "); // Confirm Input + Serial.print(N); // Repeat input for confirmation + Serial.print("\n"); // newline + break; + default: // occurs when we encounter and 'unexpected' case + Serial.print("instructions unclear you gave "); // Indicates no handling of this case + Serial.print(cmd); // prints out decimal number for future coding + Serial.print("\n"); + } + } // end serial loop +} // end main loop + +void stimulate(){ // stimulate function + digitalWrite(outs[0],HIGH); // write pin high + delay(pwidth); // wait pulse width time + digitalWrite(outs[0],LOW); // write pin low +} + +void train(){ // run a stimulation train at known intervals + for(n = 0; n < N; n++){ // run for N stims + stimulate(); // stimulate + delay(p); // delay by period and repeat + } +} From 1657a29d737c8503cca172a31e32c82b7b39c8c4 Mon Sep 17 00:00:00 2001 From: ajn2004 Date: Tue, 15 Oct 2019 11:26:19 -0400 Subject: [PATCH 05/12] Update Arduino_stim_2-1.ino minor bug corrections --- Arduino_stim_2-1/Arduino_stim_2-1.ino | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Arduino_stim_2-1/Arduino_stim_2-1.ino b/Arduino_stim_2-1/Arduino_stim_2-1.ino index 0d61a6c..cee35e2 100644 --- a/Arduino_stim_2-1/Arduino_stim_2-1.ino +++ b/Arduino_stim_2-1/Arduino_stim_2-1.ino @@ -24,10 +24,10 @@ // USer Variables int in = 1; // Specify number of inputs used int out = 4; //Specify number of outputs used -int ins[] = {13, 12}; // {Camera, Ext. Shut} +int ins[] = {13}; // {Camera, Ext. Shut} int outs[] = {7, 2, 3, 4}; // {Stimulate, Laser1, Laser2, ...} -int f = 1; // initial frequency of Stimulation in Hz -int N = 10; // Number of stimuli +int f = 20; // initial frequency of Stimulation in Hz +int N = 20; // Number of stimuli long pwidth = 1; // pulse width in milliseconds // Initialization of user independent variables. @@ -70,7 +70,6 @@ void loop() { int cmd = 0; // Command variable for updating arduino state through USB cam = digitalRead(ins[0]); // Read camera state for this frame if(cam0 != cam) { // If camera state has changed execute following - cmd = count + 5; switch(cam){ // Switch between high and low states case HIGH: // Indicates Frame is being read if(digitalRead(ins[1]) == HIGH || in == 1){ // If either 1 input or the external shutter is open @@ -90,12 +89,12 @@ void loop() { }//end switch las_stat for switcher } // end switch laser state - count++; // increment counting variable - if(count == stim){ - if(arm == 1){flag = 1;} + count++; // increment counting variable + if(count == stim){ + if(arm == 1){flag = 1;} } - Serial.print(count); // print camera frame - Serial.print("\n"); // newline character + Serial.print(count); // print camera frame + Serial.print("\n"); // newline character } break; // Don't execute any more of the switch loop @@ -167,7 +166,7 @@ void loop() { break; case 78: // if incoming bit is 'N' change number of stimuli N =Serial.parseInt(); // Parse incoming integer into N - Serial.print("Number of stimuli is not "); // Confirm Input + Serial.print("Number of stimuli is now "); // Confirm Input Serial.print(N); // Repeat input for confirmation Serial.print("\n"); // newline break; From c7327fc7c32215f211d079227d1724302aefb85f Mon Sep 17 00:00:00 2001 From: ajn2004 Date: Tue, 15 Oct 2019 13:34:10 -0400 Subject: [PATCH 06/12] Create Arduino_stim_2-2.ino --- Arduino_stim_2-2/Arduino_stim_2-2.ino | 229 ++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 Arduino_stim_2-2/Arduino_stim_2-2.ino diff --git a/Arduino_stim_2-2/Arduino_stim_2-2.ino b/Arduino_stim_2-2/Arduino_stim_2-2.ino new file mode 100644 index 0000000..1dad1f8 --- /dev/null +++ b/Arduino_stim_2-2/Arduino_stim_2-2.ino @@ -0,0 +1,229 @@ +// Arduino Stim v 2.2 +// +// This is an arduino sketch attempting to handle the electrical communication between +// an EMCCD, Isolator Battery, Coherent Laser box, in a controlled and programable fashion. +// This version is a working version that will drive up to a number of digital outputs. +// It operates by reading the rising edge of camera frame. When the camera frame is high, +// the digital signal for lasers goes high, then turn off with the camera fire line. The +// Stimulator turns on for a specified frame. +// AN 8-29-2019 Tim Ryan Lab +// +// User commands while running +// 'r' reset counting +// 's#' set frame # to new stimulation value +// 'S' stimulate train immediately +// 'f#' set frequency of train +// 'N#' set number of stimulations / train +// 'p' +// +// Change_log +// 2.2 Added inverter functionality and dual camera capability +// 2.1 Fully functional arduino program, incorporating arming protocol and streamlining communication +// 1.3 Added function generator support AJN 9-29-19 +// 1.2 Added switcher support as a switch statement AJN 9-29-19 + +// USer Variables +int in = 1; // Specify number of inputs used +int out = 4; //Specify number of outputs used +int ins[] = {13}; // {Camera, Ext. Shut} +int outs[] = {7, 2, 3, 4}; // {Stimulate, Laser1, Laser2, ...} +int f = 20; // initial frequency of Stimulation in Hz +int N = 20; // Number of stimuli +long pwidth = 1; // pulse width in milliseconds + +// Initialization of user independent variables. +unsigned int count = 0; // Initialize Frame number (no negative frames) +bool cam0 = LOW; // Initialize 'previous' camera state as low +bool cam = LOW; // Initialize 'current' state as high +bool cam20 = LOW; // Initialize 'previous' camera state as low +bool cam2 = LOW; // Initialize 'current' state as high +bool invert = LOW; +int arm = 0; +int stim = 10; // Initialize no stimulation unless asked for it (setting to -1 prevents stimulation) +int laser_state = 0; // laser state to induce switching +long lastmil = 0; // Storage variable for previous time + +unsigned long p = 1000/f; // Period between stimuli in ms +int flag = 0; // flag for timing + +int n = 0; // stimulus counting variable + + + +void setup() { + for (int i =0; i< in; i++){ // loop over inputs + pinMode(ins[i],INPUT); // activate inputs + } + for (int i =0; i< out; i++){ // activate outputs + pinMode(outs[i],OUTPUT); + digitalWrite(outs[i], LOW); // initialize outputs to low + } + + // This section is for USB communication early on and will be streamlined after debugging 8-29-19 + Serial.begin(9600); + Serial.setTimeout(100); // we won't be communicating that much, 100 ms should be fine + Serial.print("Stimulus set to frame "); + Serial.print(stim); + Serial.print("\n"); + +} + +void loop() { + + unsigned long nowt = millis(); + int cmd = 0; // Command variable for updating arduino state through USB + cam = digitalRead(ins[0]); // Read camera state for this frame + if(invert == HIGH){cam = !cam;} // invert camera signal if invert is high + if(cam0 != cam) { // If camera state has changed execute following + switch(cam){ // Switch between high and low states + case HIGH: // Indicates Frame is being read + if(digitalRead(ins[1]) == HIGH || in == 1){ // If either 1 input or the external shutter is open + switch(laser_state){ + case 0: // all on or off + for(int i=1; i < out; i++){ // Loop over laser outputs + digitalWrite(outs[i],HIGH); // write outputs to high + } + break; + case 1: //switcher between laser1 and laser2 + switch(count%2){ + case 0: + digitalWrite(outs[3],HIGH); + break; + case 1: + digitalWrite(outs[1],HIGH); + break; + }//end switch las_stat for switcher + break; + case 2: // if laser state is set to 2, we have each camera controlling it's own laser + digitalWrite(outs[1],HIGH); + } // end switch laser state + + count++; // increment counting variable + if(count == stim){ + if(arm == 1){flag = 1;} + } + Serial.print(count); // print camera frame + Serial.print("\n"); // newline character + } + break; // Don't execute any more of the switch loop + + case LOW: // Indicates the frame has finished aquistion + switch(laser_state){ + case 2: // turn off only camera's lasers + digitalWrite(outs[1],LOW); // write pin low + break; + default: // default should be all lasers off at the end of the frame + for(int i=1; i < out; i++){ // turn off lasers + digitalWrite(outs[i],LOW); // write pin low + } // all other work is taken care of on the rising edge. However if there is a use for the falling edge it would go here + break; + } + } + } // end state change section + cam0 = cam; // update previous state to current state + if(invert == HIGH){ + // Second Camera Control + cam2 = digitalRead(ins[1]); + if(cam20 != cam2) { // If camera state has changed execute following + switch(cam2){ // Switch between high and low states + case HIGH: // Indicates Frame is being read + digitalWrite(outs[2],HIGH); + break; + case LOW: + digitalWrite(outs[2],LOW); + break; + } + } + cam20 = cam2; + } + // Stimulation Section + if(flag == 1){ // if stimulation flag is high, look for stimulation behavior + if(n == 0){ // if no stimuli have been given + stimulate(); // stimulate + //Serial.print(n); + lastmil = nowt; // update time + n = n+1; // increment stim count + } + + else{ // if one stimulus has already been given, wait p amount of milliseconds + if(nowt - lastmil >= p && n0){ // if there is a usb input, execute following + cmd = Serial.read(); // Read the 1 byte input + Serial.print("Confirmed "); // Respond to USB + switch(cmd){ // switch statement allows for building of a variety of command interfaces + case 114: // if the incoming byte is 'r' + count = 0; // reset the counting variable to 0 + Serial.print("count = 0\n"); // Confirm change + break; + case 115: // If incoming byte is 's' the following bytes will be a framenumber + stim = Serial.parseInt(); // parse the bytes into integers + Serial.print("stimulus is now on frame "); // Confirm input + Serial.print(stim); // Repeat input for confirmation + Serial.print("\n"); // newline + break; + case 97: // If incoming byte is 's' the following bytes will be a framenumber + arm = (arm +1) % 2; + Serial.print("Arm is now "); // Confirm input + Serial.print(arm); // Repeat input for confirmation + Serial.print("\n"); // newline + break; + case 83: // If the incoming bit is 'S' then stimulate now + train(); // Run a train of stimuli at p intervals + Serial.print("STIM!\n"); // communicate sitmulation + break; + case 119: // If the incoming bit is 'w' then turn on/off switcher + if(laser_state == 1){laser_state = 0;} + else if(laser_state == 0 ){laser_state = 1;} + Serial.print("Switcher Toggled\n"); // Issue confirmation + break; + case 102: // if incoming bit is 'f' reset frequency + f = Serial.parseInt(); // parse the bytes into integers + p = 1000/f; // recalculate period + Serial.print("stimulus is now at "); // Confirm Input + Serial.print(f); // Repeat input for confirmation + Serial.print("Hz\n"); // newline + break; + case 78: // if incoming bit is 'N' change number of stimuli + N =Serial.parseInt(); // Parse incoming integer into N + Serial.print("Number of stimuli is now "); // Confirm Input + Serial.print(N); // Repeat input for confirmation + Serial.print("\n"); // newline + break; + case 105: // if incoming bit is 'i' toggle inverter + invert = !invert; + if(laser_state == 2){laser_state = 0;} + else{laser_state = 2;} + Serial.print("Invert is set to "); // Confirm Input + Serial.print(invert); // Repeat input for confirmation + Serial.print("\n"); // newline + break; + default: // occurs when we encounter and 'unexpected' case + Serial.print("instructions unclear you gave "); // Indicates no handling of this case + Serial.print(cmd); // prints out decimal number for future coding + Serial.print("\n"); + } + } // end serial loop +} // end main loop + +void stimulate(){ // stimulate function + digitalWrite(outs[0],HIGH); // write pin high + delay(pwidth); // wait pulse width time + digitalWrite(outs[0],LOW); // write pin low +} + +void train(){ // run a stimulation train at known intervals + for(n = 0; n < N; n++){ // run for N stims + stimulate(); // stimulate + delay(p); // delay by period and repeat + } +} From f59004ee0e5ed433b34237ac91cdcafeda55d2fb Mon Sep 17 00:00:00 2001 From: Andrew Nelson <33523882+ajn2004@users.noreply.github.com> Date: Wed, 16 Oct 2019 07:49:22 -0400 Subject: [PATCH 07/12] Update Arduino_stim_2-2.ino --- Arduino_stim_2-2/Arduino_stim_2-2.ino | 74 +++++++++++++++++++++------ 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/Arduino_stim_2-2/Arduino_stim_2-2.ino b/Arduino_stim_2-2/Arduino_stim_2-2.ino index 1dad1f8..7f14cf9 100644 --- a/Arduino_stim_2-2/Arduino_stim_2-2.ino +++ b/Arduino_stim_2-2/Arduino_stim_2-2.ino @@ -25,8 +25,9 @@ // USer Variables int in = 1; // Specify number of inputs used int out = 4; //Specify number of outputs used -int ins[] = {13}; // {Camera, Ext. Shut} +int ins[] = {13, 12}; // {Camera, Ext. Shut} int outs[] = {7, 2, 3, 4}; // {Stimulate, Laser1, Laser2, ...} +int ext_trig = 5; int f = 20; // initial frequency of Stimulation in Hz int N = 20; // Number of stimuli long pwidth = 1; // pulse width in milliseconds @@ -38,10 +39,14 @@ bool cam = LOW; // Initialize 'current' state as high bool cam20 = LOW; // Initialize 'previous' camera state as low bool cam2 = LOW; // Initialize 'current' state as high bool invert = LOW; +bool simul = LOW; +bool ext_go = LOW; int arm = 0; int stim = 10; // Initialize no stimulation unless asked for it (setting to -1 prevents stimulation) int laser_state = 0; // laser state to induce switching long lastmil = 0; // Storage variable for previous time +long lastcam = 0; +int cam_p = 100; // initialization of camera period unsigned long p = 1000/f; // Period between stimuli in ms int flag = 0; // flag for timing @@ -58,7 +63,9 @@ void setup() { pinMode(outs[i],OUTPUT); digitalWrite(outs[i], LOW); // initialize outputs to low } - + pinMode(ext_trig,OUTPUT); + digitalWrite(ext_trig,LOW); + pinMode(12,INPUT); // This section is for USB communication early on and will be streamlined after debugging 8-29-19 Serial.begin(9600); Serial.setTimeout(100); // we won't be communicating that much, 100 ms should be fine @@ -71,13 +78,22 @@ void setup() { void loop() { unsigned long nowt = millis(); + if(nowt-lastcam >= cam_p && ext_go){take_frame();} // external camera synchronization pulse + int cmd = 0; // Command variable for updating arduino state through USB + cam = digitalRead(ins[0]); // Read camera state for this frame - if(invert == HIGH){cam = !cam;} // invert camera signal if invert is high + cam2 = digitalRead(12); + + if(invert == HIGH){ + cam = !cam; + cam2 = !cam2; + } // invert camera signal if invert is high + if(cam0 != cam) { // If camera state has changed execute following switch(cam){ // Switch between high and low states case HIGH: // Indicates Frame is being read - if(digitalRead(ins[1]) == HIGH || in == 1){ // If either 1 input or the external shutter is open + // if(digitalRead(ins[1]) == HIGH || in == 1){ // If either 1 input or the external shutter is open switch(laser_state){ case 0: // all on or off for(int i=1; i < out; i++){ // Loop over laser outputs @@ -87,7 +103,7 @@ void loop() { case 1: //switcher between laser1 and laser2 switch(count%2){ case 0: - digitalWrite(outs[3],HIGH); + digitalWrite(outs[2],HIGH); break; case 1: digitalWrite(outs[1],HIGH); @@ -95,7 +111,8 @@ void loop() { }//end switch las_stat for switcher break; case 2: // if laser state is set to 2, we have each camera controlling it's own laser - digitalWrite(outs[1],HIGH); + digitalWrite(outs[3],HIGH); + break; } // end switch laser state count++; // increment counting variable @@ -104,13 +121,14 @@ void loop() { } Serial.print(count); // print camera frame Serial.print("\n"); // newline character - } + // } break; // Don't execute any more of the switch loop case LOW: // Indicates the frame has finished aquistion switch(laser_state){ case 2: // turn off only camera's lasers - digitalWrite(outs[1],LOW); // write pin low + digitalWrite(outs[3],LOW); // write pin low + digitalWrite(outs[2],LOW); break; default: // default should be all lasers off at the end of the frame for(int i=1; i < out; i++){ // turn off lasers @@ -121,21 +139,27 @@ void loop() { } } // end state change section cam0 = cam; // update previous state to current state - if(invert == HIGH){ + if(simul == HIGH){ // Second Camera Control - cam2 = digitalRead(ins[1]); + Serial.print(cam2); + Serial.print('\n'); + if(cam20 != cam2) { // If camera state has changed execute following switch(cam2){ // Switch between high and low states case HIGH: // Indicates Frame is being read - digitalWrite(outs[2],HIGH); + digitalWrite(outs[1],HIGH); + break; case LOW: - digitalWrite(outs[2],LOW); + digitalWrite(outs[1],LOW); + break; } } - cam20 = cam2; + } + cam20 = cam2; + // Stimulation Section if(flag == 1){ // if stimulation flag is high, look for stimulation behavior if(n == 0){ // if no stimuli have been given @@ -201,12 +225,26 @@ void loop() { break; case 105: // if incoming bit is 'i' toggle inverter invert = !invert; - if(laser_state == 2){laser_state = 0;} - else{laser_state = 2;} Serial.print("Invert is set to "); // Confirm Input Serial.print(invert); // Repeat input for confirmation Serial.print("\n"); // newline break; + case 101: // if incoming bit is 'e' toggle external triggering + ext_go = !ext_go; + + lastcam = nowt; + Serial.print("Ext go is set to "); // Confirm Input + Serial.print(ext_go); // Repeat input for confirmation + Serial.print("\n"); // newline + break; + case 107: // if k is in toggle simultaneous + simul = !simul; + if(laser_state == 2){laser_state = 0;} + else{laser_state = 2;} + Serial.print("Simultaneous is set to "); // Confirm Input + Serial.print(simul); // Repeat input for confirmation + Serial.print("\n"); // newline + break; default: // occurs when we encounter and 'unexpected' case Serial.print("instructions unclear you gave "); // Indicates no handling of this case Serial.print(cmd); // prints out decimal number for future coding @@ -221,6 +259,12 @@ void stimulate(){ // stimulate function digitalWrite(outs[0],LOW); // write pin low } +void take_frame(){ // stimulate function + digitalWrite(ext_trig,HIGH); // write pin high + delay(pwidth); // wait pulse width time + digitalWrite(ext_trig,LOW); // write pin low +} + void train(){ // run a stimulation train at known intervals for(n = 0; n < N; n++){ // run for N stims stimulate(); // stimulate From eb3efd95418b6b7fa63f8984afd02b0d7bf25d1e Mon Sep 17 00:00:00 2001 From: Andrew Nelson <33523882+ajn2004@users.noreply.github.com> Date: Wed, 16 Oct 2019 14:53:41 -0400 Subject: [PATCH 08/12] Finalized 2-2 Arduino 2-2 is the sketch designed for the 2-camera system on 'The Bear'. This version indicates that I have worked through it with Ryan and have a functional sketch. --- Arduino_stim_2-2/Arduino_stim_2-2.ino | 120 +++++++++++++++----------- 1 file changed, 69 insertions(+), 51 deletions(-) diff --git a/Arduino_stim_2-2/Arduino_stim_2-2.ino b/Arduino_stim_2-2/Arduino_stim_2-2.ino index 7f14cf9..1debfc4 100644 --- a/Arduino_stim_2-2/Arduino_stim_2-2.ino +++ b/Arduino_stim_2-2/Arduino_stim_2-2.ino @@ -46,7 +46,7 @@ int stim = 10; // Initialize no stimulation unless asked for it (setting to -1 int laser_state = 0; // laser state to induce switching long lastmil = 0; // Storage variable for previous time long lastcam = 0; -int cam_p = 100; // initialization of camera period +long cam_p = 100; // initialization of camera period unsigned long p = 1000/f; // Period between stimuli in ms int flag = 0; // flag for timing @@ -65,7 +65,7 @@ void setup() { } pinMode(ext_trig,OUTPUT); digitalWrite(ext_trig,LOW); - pinMode(12,INPUT); + pinMode(ins[1],INPUT); // This section is for USB communication early on and will be streamlined after debugging 8-29-19 Serial.begin(9600); Serial.setTimeout(100); // we won't be communicating that much, 100 ms should be fine @@ -78,12 +78,15 @@ void setup() { void loop() { unsigned long nowt = millis(); - if(nowt-lastcam >= cam_p && ext_go){take_frame();} // external camera synchronization pulse + if(nowt-lastcam >= cam_p && ext_go){ + take_frame(); + lastcam = nowt; + } // external camera synchronization pulse int cmd = 0; // Command variable for updating arduino state through USB cam = digitalRead(ins[0]); // Read camera state for this frame - cam2 = digitalRead(12); + cam2 = digitalRead(ins[1]); if(invert == HIGH){ cam = !cam; @@ -139,16 +142,11 @@ void loop() { } } // end state change section cam0 = cam; // update previous state to current state - if(simul == HIGH){ - // Second Camera Control - Serial.print(cam2); - Serial.print('\n'); - + if(simul == HIGH){ // if simul is high we want 2 cameras each controlling their own laser if(cam20 != cam2) { // If camera state has changed execute following switch(cam2){ // Switch between high and low states case HIGH: // Indicates Frame is being read - digitalWrite(outs[1],HIGH); - + digitalWrite(outs[1],HIGH); break; case LOW: digitalWrite(outs[1],LOW); @@ -185,30 +183,39 @@ void loop() { cmd = Serial.read(); // Read the 1 byte input Serial.print("Confirmed "); // Respond to USB switch(cmd){ // switch statement allows for building of a variety of command interfaces - case 114: // if the incoming byte is 'r' - count = 0; // reset the counting variable to 0 - Serial.print("count = 0\n"); // Confirm change - break; - case 115: // If incoming byte is 's' the following bytes will be a framenumber - stim = Serial.parseInt(); // parse the bytes into integers - Serial.print("stimulus is now on frame "); // Confirm input - Serial.print(stim); // Repeat input for confirmation - Serial.print("\n"); // newline - break; - case 97: // If incoming byte is 's' the following bytes will be a framenumber - arm = (arm +1) % 2; - Serial.print("Arm is now "); // Confirm input - Serial.print(arm); // Repeat input for confirmation - Serial.print("\n"); // newline - break; - case 83: // If the incoming bit is 'S' then stimulate now - train(); // Run a train of stimuli at p intervals - Serial.print("STIM!\n"); // communicate sitmulation - break; - case 119: // If the incoming bit is 'w' then turn on/off switcher - if(laser_state == 1){laser_state = 0;} - else if(laser_state == 0 ){laser_state = 1;} - Serial.print("Switcher Toggled\n"); // Issue confirmation + + case 78: // if incoming bit is 'N' change number of stimuli // variables and commands used + N =Serial.parseInt(); // Parse incoming integer into N // 78: N: changes number of stimuli + Serial.print("Number of stimuli is now "); // Confirm Input // 83: S: causes immediate execution of stimulation train + Serial.print(N); // Repeat input for confirmation // 97: a: changes which frame stimulation will occur on + Serial.print("\n"); // newline // 99: c#: changes the time between camera frames for external trigger + break; // 101: e: toggle external triggering + // 102: f#: sets frequency of stimulation train + case 83: // If the incoming bit is 'S' then stimulate now // 105: i: toggle inverter + train(); // Run a train of stimuli at p intervals // 107: k: toggle simultaneous camera acquisition + Serial.print("STIM!\n"); // communicate sitmulation // 114: r: reset frame number + break; // 115: s: force train of stimulation + // 119: w: toggle switcher + case 97: // If incoming byte is 'a' then arm stimulation // + arm = (arm +1) % 2; // + Serial.print("Arm is now "); // Confirm input // + Serial.print(arm); // Repeat input for confirmation // + Serial.print("\n"); // newline // + break; // + case 99: // if incoming byte is 'c' change camera cycle time (cam_p) // + cam_p = Serial.parseInt(); // + Serial.print("Delay between camera frames is now "); // + Serial.print(cam_p); // + Serial.print("ms\n"); // + break; // + // + case 101: // if incoming bit is 'e' toggle external triggering // + ext_go = !ext_go; // + lastcam = nowt; // + for(int i =1; i Date: Thu, 17 Oct 2019 14:43:03 -0400 Subject: [PATCH 09/12] Update Arduino_stim_2-1.ino --- Arduino_stim_2-1/Arduino_stim_2-1.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Arduino_stim_2-1/Arduino_stim_2-1.ino b/Arduino_stim_2-1/Arduino_stim_2-1.ino index cee35e2..4165c9e 100644 --- a/Arduino_stim_2-1/Arduino_stim_2-1.ino +++ b/Arduino_stim_2-1/Arduino_stim_2-1.ino @@ -22,10 +22,10 @@ // 1.2 Added switcher support as a switch statement AJN 9-29-19 // USer Variables -int in = 1; // Specify number of inputs used -int out = 4; //Specify number of outputs used -int ins[] = {13}; // {Camera, Ext. Shut} -int outs[] = {7, 2, 3, 4}; // {Stimulate, Laser1, Laser2, ...} +int in = 2; // Specify number of inputs used +int out = 5; //Specify number of outputs used +int ins[] = {13, 12}; // {Camera, Ext. Shut} +int outs[] = {7, 2, 3, 4,5}; // {Stimulate, Laser1, Laser2, ...} int f = 20; // initial frequency of Stimulation in Hz int N = 20; // Number of stimuli long pwidth = 1; // pulse width in milliseconds @@ -81,10 +81,10 @@ void loop() { case 1: //switcher between laser1 and laser2 switch(count%2){ case 0: - digitalWrite(outs[3],HIGH); + digitalWrite(outs[1],HIGH); break; case 1: - digitalWrite(outs[1],HIGH); + digitalWrite(outs[2],HIGH); break; }//end switch las_stat for switcher } // end switch laser state From f0999b6e4477d13f7a5710c5afc25254f003041f Mon Sep 17 00:00:00 2001 From: ajn2004 Date: Wed, 30 Oct 2019 15:34:54 -0400 Subject: [PATCH 10/12] stimulation_bug_correction --- Arduino_stim_2-1/Arduino_stim_2-1.ino | 2 +- Arduino_stim_2-2/Arduino_stim_2-2.ino | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Arduino_stim_2-1/Arduino_stim_2-1.ino b/Arduino_stim_2-1/Arduino_stim_2-1.ino index cee35e2..65e1574 100644 --- a/Arduino_stim_2-1/Arduino_stim_2-1.ino +++ b/Arduino_stim_2-1/Arduino_stim_2-1.ino @@ -149,7 +149,7 @@ void loop() { Serial.print("\n"); // newline break; case 83: // If the incoming bit is 'S' then stimulate now - train(); // Run a train of stimuli at p intervals + flag = 1; // Run a train of stimuli at p intervals Serial.print("STIM!\n"); // communicate sitmulation break; case 119: // If the incoming bit is 'w' then turn on/off switcher diff --git a/Arduino_stim_2-2/Arduino_stim_2-2.ino b/Arduino_stim_2-2/Arduino_stim_2-2.ino index 7f14cf9..a88889e 100644 --- a/Arduino_stim_2-2/Arduino_stim_2-2.ino +++ b/Arduino_stim_2-2/Arduino_stim_2-2.ino @@ -202,7 +202,7 @@ void loop() { Serial.print("\n"); // newline break; case 83: // If the incoming bit is 'S' then stimulate now - train(); // Run a train of stimuli at p intervals + flag = 1; // Run a train of stimuli at p intervals Serial.print("STIM!\n"); // communicate sitmulation break; case 119: // If the incoming bit is 'w' then turn on/off switcher From 27220ddda2cda71cd693ca7d4aa22c709d48899f Mon Sep 17 00:00:00 2001 From: Andrew Nelson <33523882+ajn2004@users.noreply.github.com> Date: Mon, 4 Nov 2019 10:35:33 -0500 Subject: [PATCH 11/12] Update Arduino_stim_2-1.ino --- Arduino_stim_2-1/Arduino_stim_2-1.ino | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Arduino_stim_2-1/Arduino_stim_2-1.ino b/Arduino_stim_2-1/Arduino_stim_2-1.ino index 0d61a6c..63ca1c9 100644 --- a/Arduino_stim_2-1/Arduino_stim_2-1.ino +++ b/Arduino_stim_2-1/Arduino_stim_2-1.ino @@ -24,10 +24,12 @@ // USer Variables int in = 1; // Specify number of inputs used int out = 4; //Specify number of outputs used -int ins[] = {13, 12}; // {Camera, Ext. Shut} +int ins[] = {13}; // {Camera, Ext. Shut} +int shut = 12; int outs[] = {7, 2, 3, 4}; // {Stimulate, Laser1, Laser2, ...} int f = 1; // initial frequency of Stimulation in Hz int N = 10; // Number of stimuli +int l405 = 0; long pwidth = 1; // pulse width in milliseconds // Initialization of user independent variables. @@ -54,7 +56,8 @@ void setup() { pinMode(outs[i],OUTPUT); digitalWrite(outs[i], LOW); // initialize outputs to low } - + pinMode(shut,OUTPUT); + digitalWrite(shut,LOW); // This section is for USB communication early on and will be streamlined after debugging 8-29-19 Serial.begin(9600); Serial.setTimeout(100); // we won't be communicating that much, 100 ms should be fine @@ -153,6 +156,17 @@ void loop() { train(); // Run a train of stimuli at p intervals Serial.print("STIM!\n"); // communicate sitmulation break; + case 52: // If the incoming bit is 'S' then stimulate now + l405 = (l405+1)%2; + if(l405 == 1){ + digitalWrite(shut,HIGH); + Serial.print("405 ON\n"); + } + if(l405 == 0){ + digitalWrite(shut,LOW); + Serial.print("405 OFF\n"); + } + break; case 119: // If the incoming bit is 'w' then turn on/off switcher if(laser_state == 1){laser_state = 0;} else if(laser_state == 0 ){laser_state = 1;} From 84feea78755ead06dd68da7bc4ef3175c7c6f316 Mon Sep 17 00:00:00 2001 From: Andrew Nelson <33523882+ajn2004@users.noreply.github.com> Date: Wed, 6 Nov 2019 08:01:14 -0500 Subject: [PATCH 12/12] Create Arduino_stim_2-3.ino --- Arduino_stim_2-3/Arduino_stim_2-3.ino | 313 ++++++++++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100644 Arduino_stim_2-3/Arduino_stim_2-3.ino diff --git a/Arduino_stim_2-3/Arduino_stim_2-3.ino b/Arduino_stim_2-3/Arduino_stim_2-3.ino new file mode 100644 index 0000000..3a857a0 --- /dev/null +++ b/Arduino_stim_2-3/Arduino_stim_2-3.ino @@ -0,0 +1,313 @@ +// Arduino Stim v 2.3 +// +// This is an arduino sketch attempting to handle the electrical communication between +// an EMCCD, Isolator Battery, Coherent Laser box, in a controlled and programable fashion. +// This version is a working version that will drive up to a number of digital outputs. +// It operates by reading the rising edge of camera frame. When the camera frame is high, +// the digital signal for lasers goes high, then turn off with the camera fire line. The +// Stimulator turns on for a specified frame. +// AN 8-29-2019 Tim Ryan Lab +// +// User commands while running +// 'r' reset counting +// 's#' set frame # to new stimulation value +// 'S' stimulate train immediately +// 'f#' set frequency of train +// 'N#' set number of stimulations / train +// 'p' +// +// Change_log +// 2.3 Altered 2.2 to allow triggering on superres scope +// 2.2 Added inverter functionality and dual camera capability +// 2.1 Fully functional arduino program, incorporating arming protocol and streamlining communication +// 1.3 Added function generator support AJN 9-29-19 +// 1.2 Added switcher support as a switch statement AJN 9-29-19 + +// USer Variables +int in = 1; // Specify number of inputs used +int out = 4; //Specify number of outputs used +int ins[] = {13,11}; // {Camera, Ext. Shut} +int outs[] = {7, 4, 2, 3}; // {Stimulate, Laser1, Laser2, ...} +int ext_trig = 10; +int shut = 12; +int f = 20; // initial frequency of Stimulation in Hz +int N = 20; // Number of stimuli +long pwidth = 1; // pulse width in milliseconds + +// Initialization of user independent variables. +unsigned int count = 0; // Initialize Frame number (no negative frames) +bool cam0 = LOW; // Initialize 'previous' camera state as low +bool cam = LOW; // Initialize 'current' state as high +bool cam20 = LOW; // Initialize 'previous' camera state as low +bool cam2 = LOW; // Initialize 'current' state as high +bool invert = LOW; +bool simul = LOW; +bool ext_go = LOW; +int arm = 0; +int stim = 10; // Initialize no stimulation unless asked for it (setting to -1 prevents stimulation) +int laser_state = 0; // laser state to induce switching +long lastmil = 0; // Storage variable for previous time +long lastcam = 0; +long cam_p = 100; // initialization of camera period +int l405 =0; +unsigned long p = 1000/f; // Period between stimuli in ms +int flag = 0; // flag for timing + +int n = 0; // stimulus counting variable + + + +void setup() { + for (int i =0; i< in; i++){ // loop over inputs + pinMode(ins[i],INPUT); // activate inputs + } + for (int i =0; i< out; i++){ // activate outputs + pinMode(outs[i],OUTPUT); + digitalWrite(outs[i], LOW); // initialize outputs to low + } + pinMode(ext_trig,OUTPUT); + digitalWrite(ext_trig,LOW); + pinMode(ins[1],INPUT); + pinMode(shut,OUTPUT); + digitalWrite(shut, LOW); + // This section is for USB communication early on and will be streamlined after debugging 8-29-19 + Serial.begin(9600); + Serial.setTimeout(100); // we won't be communicating that much, 100 ms should be fine + Serial.print("Stimulus set to frame "); + Serial.print(stim); + Serial.print("\n"); + +} + +void loop() { + + unsigned long nowt = millis(); + if(nowt-lastcam >= cam_p && ext_go){ + take_frame(); + lastcam = nowt; + } // external camera synchronization pulse + + int cmd = 0; // Command variable for updating arduino state through USB + + cam = digitalRead(ins[0]); // Read camera state for this frame + cam2 = digitalRead(ins[1]); + + if(invert == HIGH){ + cam = !cam; + cam2 = !cam2; + } // invert camera signal if invert is high + + if(cam0 != cam) { // If camera state has changed execute following + switch(cam){ // Switch between high and low states + case HIGH: // Indicates Frame is being read + // if(digitalRead(ins[1]) == HIGH || in == 1){ // If either 1 input or the external shutter is open + switch(laser_state){ + case 0: // all on or off + for(int i=1; i < out; i++){ // Loop over laser outputs + digitalWrite(outs[i],HIGH); // write outputs to high + } + break; + case 1: //switcher between laser1 and laser2 + switch(count%2){ + case 0: + digitalWrite(outs[2],HIGH); + break; + case 1: + digitalWrite(outs[1],HIGH); + break; + }//end switch las_stat for switcher + break; + case 2: // if laser state is set to 2, we have each camera controlling it's own laser + digitalWrite(outs[3],HIGH); + break; + } // end switch laser state + + count++; // increment counting variable + if(count == stim){ + if(arm == 1){flag = 1;} + } + Serial.print(count); // print camera frame + Serial.print("\n"); // newline character + // } + break; // Don't execute any more of the switch loop + + case LOW: // Indicates the frame has finished aquistion + switch(laser_state){ + case 2: // turn off only camera's lasers + digitalWrite(outs[3],LOW); // write pin low + digitalWrite(outs[2],LOW); + break; + default: // default should be all lasers off at the end of the frame + for(int i=1; i < out; i++){ // turn off lasers + digitalWrite(outs[i],LOW); // write pin low + } // all other work is taken care of on the rising edge. However if there is a use for the falling edge it would go here + break; + } + } + } // end state change section + cam0 = cam; // update previous state to current state + if(simul == HIGH){ // if simul is high we want 2 cameras each controlling their own laser + if(cam20 != cam2) { // If camera state has changed execute following + switch(cam2){ // Switch between high and low states + case HIGH: // Indicates Frame is being read + digitalWrite(outs[1],HIGH); + break; + case LOW: + digitalWrite(outs[1],LOW); + + break; + } + } + + } + cam20 = cam2; + + // Stimulation Section + if(flag == 1){ // if stimulation flag is high, look for stimulation behavior + if(n == 0){ // if no stimuli have been given + stimulate(); // stimulate + //Serial.print(n); + lastmil = nowt; // update time + n = n+1; // increment stim count + } + + else{ // if one stimulus has already been given, wait p amount of milliseconds + if(nowt - lastmil >= p && n0){ // if there is a usb input, execute following + cmd = Serial.read(); // Read the 1 byte input + Serial.print("Confirmed "); // Respond to USB + switch(cmd){ // switch statement allows for building of a variety of command interfaces + + case 52: // If the incoming bit is '4' then toggle 405 shutter + l405 = (l405+1)%2; + if(l405 == 1){ + digitalWrite(shut,HIGH); + Serial.print("405 ON\n"); + } + if(l405 == 0){ + digitalWrite(shut,LOW); + Serial.print("405 OFF\n"); + } + break; + // variables and commands used + case 78: // if incoming bit is 'N' change number of stimuli // 55: 4: Toggle 405 shutter + N =Serial.parseInt(); // Parse incoming integer into N // 78: N: changes number of stimuli + Serial.print("Number of stimuli is now "); // Confirm Input // 83: S: causes immediate execution of stimulation train + Serial.print(N); // Repeat input for confirmation // 97: a: changes which frame stimulation will occur on + Serial.print("\n"); // newline // 99: c#: changes the time between camera frames for external trigger + break; // 101: e: toggle external triggering + // 102: f#: sets frequency of stimulation train + case 83: // If the incoming bit is 'S' then stimulate now // 105: i: toggle inverter + flag = 1; // Run a train of stimuli at p intervals // 107: k: toggle simultaneous camera acquisition + Serial.print("STIM!\n"); // communicate sitmulation // 114: r: reset frame number + break; // 115: s: force train of stimulation + // 116: t: force external trigger + case 97: // If incoming byte is 'a' then arm stimulation // 119: w: toggle switcher + arm = (arm +1) % 2; // + Serial.print("Arm is now "); // Confirm input // + Serial.print(arm); // Repeat input for confirmation // + Serial.print("\n"); // newline // + break; + // + case 99: // if incoming byte is 'c' change camera cycle time (cam_p) // + cam_p = Serial.parseInt(); // + Serial.print("Delay between camera frames is now "); // + Serial.print(cam_p); // + Serial.print("ms\n"); // + break; // + // + case 101: // if incoming bit is 'e' toggle external triggering // + ext_go = !ext_go; // + lastcam = nowt; // + for(int i =1; i