목록Systems Neuroscience/ARDUINO functions (9)
LuckyFace's Systems Lifescience
// Task state else if (state = timeStart+duration[state]) { // is current duration(=time-timeStart) longer than epoch duration? timeStart = times; // reset epoch start time select창에 s를 치면 state는 6으로 변경됨.따라서 큰 if/else if 함수에서 state 0: base else if (state==6) { if (iTrial>=nTrial) { // if current trial numb..
// Sensor read cursensor = bitRead(PINB,sensorPin); if (cursensor & ~prevsensor) { printf("%lul1\n",times); prevsensor = cursensor; if (state==2) { outcome = true; } // if sensor is touched during delay state, make outcome true. else, it is omitted trial. if (waterClear == false) { waterClear = true; } } // sensor is turned on else if (~cursensor & prevsensor) { prevsensor = cursensor; } // sens..
// portD (pin 0-7)#define odorPin0 2 // Normally-open valve that transmit fresh air#define odorPin1 3 // cue 1#define odorPin2 4 // cue 2#define odorPin3 5 // cue 3#define odorPin4 6 // cue 4#define odorPin5 7 // final valve // portB (pin 8-13)#define rewardPin 1#define punishmentPin 0#define noRewardPin 2 // used for cheetah notification#define sensorPin 4 // pin 12#define laserPin 5 // pin 13 ..
void loop() { // Standby state if (state==9) { if (Serial.available() > 0) { select = Serial.read(); // water valve on if (select == 'w') { inivalveDuration = Serial.parseInt(); if (inivalveDuration == 0) { inivalveDuration = valveDuration; } valveOn(inivalveDuration); } void valveOn(unsigned long valveDuration){ bitSet(PORTB,rewardPin); delay(valveDuration); bitClear(PORTB,rewardPin);} loop함수가 ..
void setup() { Serial.begin(115200); // serial setup fdev_setup_stream(&serial_stdout, serial_putchar, NULL, _FDEV_SETUP_WRITE); // printf setup (do not edit) stdout = &serial_stdout; // printf setup (do not edit) randomSeed(analogRead(0)); // determines seed number of random function // Pin setup DDRD = B11111110; // Pin 7, 6, 5, 4, 3, 2, 1, 0. Pin 0 and 1 is reserved for serial communication. ..
int light = 0; // 0: no light, 1: cue light, 2: reward lightint lightType = 0; // 1: cue or reward period, 2: cue period, 3: reward periodboolean noC = false;boolean reward = 0; // reward in current trialboolean outcome = 0; // did mouse lick during delay period?boolean waterClear = true; // did mouse lick after water reward? if not, do not give additional waterunsigned long times = 0; // curren..
//// Task related variablesint nTrial = 200; // total trial numberint nCue = 2; // cue number (1, 2, 4)unsigned long valveDuration = 130;unsigned long duration[7] = {500000,1000000,500000,500000,130000,2370000,2000000}; // epoch durationunsigned long rewardProbability[4] = {100, 0, 100, 0}; // unit: percentunsigned long rewardAmount[11] = {0, 30000, 42000, 53000, 64000, 77000, 86000, 92000, 1000..
#define odorPin0 2 // Normally-open valve that transmit fresh air#define odorPin1 3 // cue 1#define odorPin2 4 // cue 2#define odorPin3 5 // cue 3#define odorPin4 6 // cue 4#define odorPin5 7 // final valve // portB (pin 8-13)#define rewardPin 1#define punishmentPin 0#define noRewardPin 2 // used for cheetah notification#define sensorPin 4 // pin 12#define laserPin 5 // pin 13 ARDUINO code의 시작은 ..
내가 Systems neuroscience lab에 들어온지도 어언? 2년이란 시간이 지났다. 현재 내 첫번째 프로젝트에 쓰인 maze에는 아두이노가 핵심적인 역할을 하는데.. 사실 이 기본적인 틀은 내 사수인 도형이형이 다 만들어놓은 것이다. ARDUINO를 matlab을 이용해 control하는 platform인데, 거의 가져다 썼다는 표현이 맞을듯!! 이제 새로운 프로젝트를 시작하는데, 이 아두이노를 기본적으로 다룰줄 알아야겠다. matlab도 너무 아마추어처럼 사용한 측면이 강한데... 아두이노는 처음부터 정리해봐야겠다. 따라서 이 section에는 도형이형이 남기곤 ARDUINO code와 MATLAB code를 이해하고 정리하는 것으로 시작하여, 새로운 code를 교정해보는 것으로 마무리해볼까..