From c18628a83e4bf79a8318a5f40fcc0ade698aee32 Mon Sep 17 00:00:00 2001 From: Jon Kuziek Date: Thu, 16 Jan 2020 18:39:36 -0700 Subject: [PATCH 1/2] stimuli and delays will be longer to help saveToCSV save triggers properly f --- .../components/EEGEduEvoked/sketchEvoked.js | 81 +++++++++++-------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/src/components/PageSwitcher/components/EEGEduEvoked/sketchEvoked.js b/src/components/PageSwitcher/components/EEGEduEvoked/sketchEvoked.js index 30c1dfec..ddfe4f55 100644 --- a/src/components/PageSwitcher/components/EEGEduEvoked/sketchEvoked.js +++ b/src/components/PageSwitcher/components/EEGEduEvoked/sketchEvoked.js @@ -9,10 +9,11 @@ export default function sketchEvoked (p) { let newOnset = true; let startTime = 0; let targCount = 0; + let waitForStim = 0; p.setup = function () { p.createCanvas(300, 300); - p.frameRate(60); + p.frameRate(30); p.noStroke(); }; @@ -30,50 +31,66 @@ export default function sketchEvoked (p) { p.draw = function () { - if (p.keyIsPressed === true) { window.responseMarker = p.keyCode; } else { window.responseMarker = 0; } - p.background(255); + x = x+1; - ellapsedTime = p.millis()-startTime; - if (ellapsedTime > nextDelay) { - newOnset = true; + if (waitForStim == 1){ + if (p.millis() - startTime > 500){ + waitForStim = 0; + p.background(255); + ellapsedTime = p.millis()-startTime; + p.fill(255, 255, 255); + window.marker = 0; + p.ellipse(p.width/2, p.height/2, 300); + p.fill(255,0,0); + p.text("+", p.width/2, p.height/2); + } } else { - newOnset = false; - } - - if (newOnset) { - targCount++; - nextDelay = 500 + p.int(p.random() * 1000); - console.log(targCount, nextDelay) - startTime = p.millis(); + p.background(255); + ellapsedTime = p.millis()-startTime; - thisRand = p.random(); - if (thisRand < targProp) { // targets 20% of the time - isTarget = true; + if (ellapsedTime > nextDelay) { + newOnset = true; } else { - isTarget = false; + newOnset = false; } - if (isTarget) { - p.fill(250, 150, 150); - window.marker = 20; - } else { - p.fill(150,150,250); - window.marker = 10; + if (newOnset) { + targCount++; + nextDelay = 1500 + p.int(p.random() * 1000); + //console.log(targCount, nextDelay) + + startTime = p.millis(); + waitForStim = 1; + + thisRand = p.random(); + if (thisRand < targProp) { // targets 20% of the time + isTarget = true; + } else { + isTarget = false; + } + + if (isTarget) { + p.fill(250, 150, 150); + window.marker = 20; + } else { + p.fill(150,150,250); + window.marker = 10; + } + + } else { // during time between targets + p.fill(255, 255, 255); + window.marker = 0; } - } else { // during time between targets - p.fill(255, 255, 255); - window.marker = 0; - } - p.ellipse(p.width/2, p.height/2, 300); - p.fill(255,0,0); - p.text("+", p.width/2, p.height/2); + p.ellipse(p.width/2, p.height/2, 300); + p.fill(255,0,0); + p.text("+", p.width/2, p.height/2); + }. } - }; \ No newline at end of file From 2813a0cc76c696610966abf724893f4cc11e0ac0 Mon Sep 17 00:00:00 2001 From: Kyle Mathewson Date: Thu, 16 Jan 2020 19:58:39 -0700 Subject: [PATCH 2/2] modified code to clean up but same functionality --- src/components/PageSwitcher/PageSwitcher.js | 2 +- .../components/EEGEduEvoked/sketchEvoked.js | 117 ++++++++++-------- 2 files changed, 63 insertions(+), 56 deletions(-) diff --git a/src/components/PageSwitcher/PageSwitcher.js b/src/components/PageSwitcher/PageSwitcher.js index 28bb64e8..42ce7b5a 100644 --- a/src/components/PageSwitcher/PageSwitcher.js +++ b/src/components/PageSwitcher/PageSwitcher.js @@ -78,7 +78,7 @@ export function PageSwitcher() { const [status, setStatus] = useState(generalTranslations.connect); // for picking a new module - const [selected, setSelected] = useState(intro); + const [selected, setSelected] = useState(evoked); const handleSelectChange = useCallback(value => { setSelected(value); diff --git a/src/components/PageSwitcher/components/EEGEduEvoked/sketchEvoked.js b/src/components/PageSwitcher/components/EEGEduEvoked/sketchEvoked.js index ddfe4f55..bc3a2edb 100644 --- a/src/components/PageSwitcher/components/EEGEduEvoked/sketchEvoked.js +++ b/src/components/PageSwitcher/components/EEGEduEvoked/sketchEvoked.js @@ -1,8 +1,11 @@ export default function sketchEvoked (p) { - let x = 0; + const targProp = 0.25; + const stimDuration = 500; + const minISI = 1500; + const maxISI = 2500; + let thisRand = 0.5; //for random choice of target type - let targProp = 0.25; let isTarget = false; let ellapsedTime = 0; let nextDelay = 1000; @@ -11,6 +14,7 @@ export default function sketchEvoked (p) { let targCount = 0; let waitForStim = 0; + p.setup = function () { p.createCanvas(300, 300); p.frameRate(30); @@ -22,12 +26,12 @@ export default function sketchEvoked (p) { } p.touchStarted = function() { - if (window.touchMarker === 0) { - window.touchMarker = 255; - } else { - window.touchMarker = 0; + if (window.touchMarker === 0) { + window.touchMarker = 255; + } else { + window.touchMarker = 0; + } } -} p.draw = function () { @@ -37,60 +41,63 @@ export default function sketchEvoked (p) { window.responseMarker = 0; } - x = x+1; - - if (waitForStim == 1){ - if (p.millis() - startTime > 500){ - waitForStim = 0; - p.background(255); - ellapsedTime = p.millis()-startTime; - p.fill(255, 255, 255); - window.marker = 0; - p.ellipse(p.width/2, p.height/2, 300); - p.fill(255,0,0); - p.text("+", p.width/2, p.height/2); - } + // how lnog has it been since last target onset + ellapsedTime = p.millis()-startTime; + + if (ellapsedTime < stimDuration) { + waitForStim = true; } else { - p.background(255); - ellapsedTime = p.millis()-startTime; + waitForStim = false; + } - if (ellapsedTime > nextDelay) { - newOnset = true; + // If time to present next stimulus + if (ellapsedTime > nextDelay) { + newOnset = true; + } else { + newOnset = false; + } + + // if this draw is the start of a new target onset + if (newOnset) { + + // pick a new delay for next trial(1500-2500 ms) + nextDelay = minISI + p.int(p.random() * (maxISI-minISI)); + // timer for interstimulus interval + startTime = p.millis(); + + // log for testing + targCount++; + console.log(targCount, nextDelay) + + // Decide if target or standard + thisRand = p.random(); + if (thisRand < targProp) { // targets 20% of the time + isTarget = true; } else { - newOnset = false; + isTarget = false; } + } - if (newOnset) { - targCount++; - nextDelay = 1500 + p.int(p.random() * 1000); - //console.log(targCount, nextDelay) - - startTime = p.millis(); - waitForStim = 1; - - thisRand = p.random(); - if (thisRand < targProp) { // targets 20% of the time - isTarget = true; - } else { - isTarget = false; - } - - if (isTarget) { - p.fill(250, 150, 150); - window.marker = 20; - } else { - p.fill(150,150,250); - window.marker = 10; - } - - } else { // during time between targets - p.fill(255, 255, 255); - window.marker = 0; + // pick colour and assign marker number + // if stim just came on or staying on + if (waitForStim) { + if (isTarget) { + p.fill(250, 150, 150); + window.marker = 20; + } else { + p.fill(150,150,250); + window.marker = 10; } + // all other times + } else { + p.fill(255, 255, 255); + window.marker = 0; + } - p.ellipse(p.width/2, p.height/2, 300); - p.fill(255,0,0); - p.text("+", p.width/2, p.height/2); - }. + //actually draw the circle or blank, then fixation + p.background(255); + p.ellipse(p.width/2, p.height/2, 300); + p.fill(255,0,0); + p.text("+", p.width/2, p.height/2); } }; \ No newline at end of file