From 0bd3a13c0bf57cfe0d22417c5ca64e431f7805ce Mon Sep 17 00:00:00 2001 From: Haldrup-tech Date: Tue, 24 Sep 2024 14:07:42 -0400 Subject: [PATCH] Added Lab5 items --- .DS_Store | Bin 6148 -> 6148 bytes Research/test.py | 90 ++++++++++++ csci218/Labs/.DS_Store | Bin 6148 -> 8196 bytes .../{ => Lab4}/triangleArea/triangleArea.ino | 0 .../Lab5/AlternatingLEDs/AlternatingLEDs.ino | 21 +++ .../Lab5/CustomBinayLED/CustomBinayLED.ino | 35 +++++ csci218/Labs/Lab5/FIzzBuzz/FIzzBuzz.ino | 40 ++++++ csci218/Labs/Lab5/LEDsForLoop/LEDsForLoop.ino | 28 ++++ csci218/Labs/Lab5/LEDsOddEven/LEDsOddEven.ino | 35 +++++ csci218/Labs/Lab5/a.out | Bin 0 -> 33816 bytes csci218/Labs/Lab5/lab5.c | 131 ++++++++++++++++++ 11 files changed, 380 insertions(+) create mode 100644 Research/test.py rename csci218/Labs/{ => Lab4}/triangleArea/triangleArea.ino (100%) create mode 100644 csci218/Labs/Lab5/AlternatingLEDs/AlternatingLEDs.ino create mode 100644 csci218/Labs/Lab5/CustomBinayLED/CustomBinayLED.ino create mode 100644 csci218/Labs/Lab5/FIzzBuzz/FIzzBuzz.ino create mode 100644 csci218/Labs/Lab5/LEDsForLoop/LEDsForLoop.ino create mode 100644 csci218/Labs/Lab5/LEDsOddEven/LEDsOddEven.ino create mode 100755 csci218/Labs/Lab5/a.out create mode 100644 csci218/Labs/Lab5/lab5.c diff --git a/.DS_Store b/.DS_Store index 1d7ed1cea89149fe56426a59f9139905ccf0eba1..762e8751df0aba3cf734bfb9c3ccc1fd27d4ce86 100644 GIT binary patch delta 179 zcmZoMXfc@J&&abeU^g=(&t@K$Os0Ac1}}yH20w;i1_cH~1_K7eoOHwBdPmZhi^@bz%@p3o=kGom|BBcQZT3Uw#0y-6anI delta 31 ncmZoMXfc@J&&aVcU^g=($7UXuOs2`a?7t>9%-GD%@s}R}orwxx diff --git a/Research/test.py b/Research/test.py new file mode 100644 index 0000000..bce3213 --- /dev/null +++ b/Research/test.py @@ -0,0 +1,90 @@ +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.animation import FuncAnimation + +# Parameters for the bead motion and detector +velocity = 0.11 # Velocity of the bead (m/s) +sensor_width = 2e-4 # Sensor width (2 mm) +t_pass = 2e-3 # Time for bead to pass the sensor (2 ms) +t = np.linspace(0, t_pass, 1000) # Time array for the bead passing +bead_position = velocity * t # Position of the bead as a function of time + +# Capacitance baseline (C_real) - assume a value for illustration +epsilon_0 = 8.85e-12 # Vacuum permittivity (F/m) +r = 1e-3 # Radius of the silica bead (1 mm) +epsilon_r = 4 # Relative permittivity of silica +C_real = 4 * np.pi * epsilon_0 * epsilon_r * r # Static capacitance in Farads + +# Capacitance change as bead passes (Gaussian profile) +cap_center = sensor_width / 2 # Sensor center at half the width +cap_variation = np.exp(-((bead_position - cap_center) ** 2) / (2 * (sensor_width / 4) ** 2)) +C_time_varying = C_real * (1 + 0.1 * cap_variation) # Scaled around the base capacitance + +# Input AC signal parameters +I = 1e-6 # 1 microampere constant current +signal_freq = 1e6 # Signal frequency (1 MHz) +omega = 2 * np.pi * signal_freq # Angular frequency for 1 MHz +V_in = np.sin(omega * t) # Input AC voltage signal (sinusoidal) + +# Voltage response as the bead passes through the detector +V_time_varying = I * V_in / (1j * omega * C_time_varying) # Voltage response depends on time-varying C + +# Get the magnitude of the voltage response +V_magnitude = np.abs(V_time_varying) # Magnitude combines real and imaginary parts + +# Set up the figure and axis +fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(6, 10)) + +# Bead position plot +ax1.set_xlim(0, sensor_width) +ax1.set_ylim(-0.1, 1.1) +bead_line, = ax1.plot([], [], 'bo', label="Bead") +ax1.set_title("Bead Passing Through the Detector") +ax1.set_xlabel("Position (m)") +ax1.set_ylabel("Bead") +ax1.legend() + +# Capacitance plot +ax2.set_xlim(0, t_pass * 1e3) +ax2.set_ylim(min(C_time_varying), max(C_time_varying) * 1.1) +cap_line, = ax2.plot([], [], 'r-', label="Capacitance") +ax2.set_title("Capacitance Change Over Time") +ax2.set_xlabel("Time (ms)") +ax2.set_ylabel("Capacitance (F)") +ax2.legend() + +# Voltage response plot (magnitude) +ax3.set_xlim(0, t_pass * 1e3) +ax3.set_ylim(0, np.max(V_magnitude) * 1.1) # Plot the magnitude with scaling +voltage_line, = ax3.plot([], [], 'g-', label="Voltage Response (Magnitude)") +ax3.set_title("Voltage Response Over Time (Magnitude)") +ax3.set_xlabel("Time (ms)") +ax3.set_ylabel("Voltage (V)") +ax3.legend() + +# Initialize function for the animation +def init(): + bead_line.set_data([], []) + cap_line.set_data([], []) + voltage_line.set_data([], []) + return bead_line, cap_line, voltage_line + +# Update function for the animation +def update(frame): + # Update the bead position (needs to be a sequence, even for a single point) + bead_line.set_data([bead_position[frame]], [0.5]) + + # Update the capacitance plot + cap_line.set_data(t[:frame] * 1e3, C_time_varying[:frame]) + + # Update the voltage response plot (magnitude) + voltage_line.set_data(t[:frame] * 1e3, V_magnitude[:frame]) + + return bead_line, cap_line, voltage_line + +# Create the animation +anim = FuncAnimation(fig, update, frames=len(t), init_func=init, blit=True, interval=20) + +# Show the animation +plt.tight_layout() +plt.show() diff --git a/csci218/Labs/.DS_Store b/csci218/Labs/.DS_Store index 0bbaf4538daed1a7f46aeb8882eda9774ffb7723..4d4d3d478f8a1d9dcd6bf533d7791748447e1c02 100644 GIT binary patch delta 236 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8FDWo2aMAD7rCVH}hr%jz7$c**Q2S7O*gi zZsuXR%~;RE;KPu}ki=k`lWrKCoS$0&)CB`@x!imgm!zEhB%lPx5o_^3uLF)b0@+CN zDR|`zGBC{MUM9 KHplbKVFmyrtTIsm delta 108 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5sJ6q~50$SAlmU^g?P;AS3y+l-szg-$R| u%!ydc&cPwb3{(XK0^C5t6{KNf;&v1qd=xJY>wxd!wdijRT2sS diff --git a/csci218/Labs/triangleArea/triangleArea.ino b/csci218/Labs/Lab4/triangleArea/triangleArea.ino similarity index 100% rename from csci218/Labs/triangleArea/triangleArea.ino rename to csci218/Labs/Lab4/triangleArea/triangleArea.ino diff --git a/csci218/Labs/Lab5/AlternatingLEDs/AlternatingLEDs.ino b/csci218/Labs/Lab5/AlternatingLEDs/AlternatingLEDs.ino new file mode 100644 index 0000000..00b962f --- /dev/null +++ b/csci218/Labs/Lab5/AlternatingLEDs/AlternatingLEDs.ino @@ -0,0 +1,21 @@ +const int LED1 = 10; +const int LED2 = 11; + +const int DELAY = 1000; + +void setup() { + // put your setup code here, to run once: + pinMode(LED1, OUTPUT); + pinMode(LED2, OUTPUT); +} + +void loop() { + // put your main code here, to run repeatedly: + digitalWrite(LED1, HIGH); + digitalWrite(LED2, LOW); + delay(DELAY); + digitalWrite(LED1, LOW); + digitalWrite(LED2, HIGH); + delay(DELAY); + +} diff --git a/csci218/Labs/Lab5/CustomBinayLED/CustomBinayLED.ino b/csci218/Labs/Lab5/CustomBinayLED/CustomBinayLED.ino new file mode 100644 index 0000000..5cc679b --- /dev/null +++ b/csci218/Labs/Lab5/CustomBinayLED/CustomBinayLED.ino @@ -0,0 +1,35 @@ +const int START_LED = 2; +const int END_LED = 8; +const float DELAY = .3 * 1000; + + +void setup() { + Serial.begin(9600); + // put your setup code here, to run once: + for (int i = START_LED; i <= END_LED; i++) { + pinMode(i, OUTPUT); + digitalWrite(i, LOW); + } +} + +void loop() { + // put your main code here, to run repeatedly: + for (int i = 0; i < 128; i++) { + int num = i; + Serial.print(i); + Serial.print(" "); + for (int j = 6; j >= 0; j--) { + if (num - pow(2,j) >= 0) { + digitalWrite(START_LED + j, HIGH); + Serial.print("1"); + num -= pow(2,j); + } else { + Serial.print("0"); + digitalWrite(START_LED + j, LOW); + } + } + Serial.println(); + delay(DELAY); + } + +} diff --git a/csci218/Labs/Lab5/FIzzBuzz/FIzzBuzz.ino b/csci218/Labs/Lab5/FIzzBuzz/FIzzBuzz.ino new file mode 100644 index 0000000..91b5c47 --- /dev/null +++ b/csci218/Labs/Lab5/FIzzBuzz/FIzzBuzz.ino @@ -0,0 +1,40 @@ +const int LED1 = 10; +const int LED2 = 11; + +const int DELAY = 500; + +int i = 1; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + pinMode(LED1, OUTPUT); + pinMode(LED2, OUTPUT); +} + +void loop() { + // put your main code here, to run repeatedly: + if (!(i % 3) && !(i % 5)) { + Serial.println("FizzBuzz"); + digitalWrite(LED1, HIGH); + digitalWrite(LED2, HIGH); + } else if (!(i % 3)) { + Serial.println("Fizz"); + digitalWrite(LED1, HIGH); + digitalWrite(LED2, LOW); + } else if (!(i % 5)) { + Serial.println("Buzz"); + digitalWrite(LED1, LOW); + digitalWrite(LED2, HIGH); + } else { + Serial.println(i); + digitalWrite(LED1, LOW); + digitalWrite(LED2, LOW); + } + i++; + if (i == 31) { + i = 1; + } + delay(DELAY); + +} diff --git a/csci218/Labs/Lab5/LEDsForLoop/LEDsForLoop.ino b/csci218/Labs/Lab5/LEDsForLoop/LEDsForLoop.ino new file mode 100644 index 0000000..a7f469f --- /dev/null +++ b/csci218/Labs/Lab5/LEDsForLoop/LEDsForLoop.ino @@ -0,0 +1,28 @@ + +const int START_LED = 2; +const int END_LED = 8; +const int DELAY = 1 * 1000; + + +void setup() { + // put your setup code here, to run once: + for (int i = START_LED; i <= END_LED; i++) { + pinMode(i, OUTPUT); + digitalWrite(i, LOW); + } + +} + +void loop() { + // put your main code here, to run repeatedly: + for (int i = START_LED; i <= END_LED; i++) { + digitalWrite(i, HIGH); + delay(DELAY); + } + + for (int i = END_LED; i >= START_LED; i--) { + digitalWrite(i, LOW); + delay(DELAY); + } + +} diff --git a/csci218/Labs/Lab5/LEDsOddEven/LEDsOddEven.ino b/csci218/Labs/Lab5/LEDsOddEven/LEDsOddEven.ino new file mode 100644 index 0000000..4e52d8c --- /dev/null +++ b/csci218/Labs/Lab5/LEDsOddEven/LEDsOddEven.ino @@ -0,0 +1,35 @@ +const int START_LED = 2; +const int END_LED = 8; +const int DELAY = 1 * 1000; + + +void setup() { + // put your setup code here, to run once: + for (int i = START_LED; i <= END_LED; i++) { + pinMode(i, OUTPUT); + digitalWrite(i, LOW); + } + +} + +void loop() { + // put your main code here, to run repeatedly: + for (int i = START_LED; i <= END_LED; i++) { + if (i % 2) { + digitalWrite(i, HIGH); + } else { + digitalWrite(i, LOW); + } + } + delay(DELAY); + for (int i = START_LED; i <= END_LED; i++) { + if (!(i % 2)) { + digitalWrite(i, HIGH); + } else { + digitalWrite(i, LOW); + } + } + delay(DELAY); + + +} diff --git a/csci218/Labs/Lab5/a.out b/csci218/Labs/Lab5/a.out new file mode 100755 index 0000000000000000000000000000000000000000..6ebfc50a11fb4f2dec259efc7d1fdf595b4ef675 GIT binary patch literal 33816 zcmeI5Yiv}<702hUA6c&rnAEB<5HX<;mX_KO$JkyH$4>>*f*r6Lt0}##z1Q}_de`jU z#Sdt+g`k)uAABoISXCvEs-`%!soSQFsT$Q0YSiXK8(M|XstPS?BS%rBqE?j%G4B7& zz1OTac1@}B?HqJ=&Y8!VGrt-0ZRY;&!w+s12%!mx2f7j}vxPV*BrG9HpgW#%E${o$tveSP(JGXs9GT&5+X(U(Js?E%N>6V{s4SpvkEG|Aq4H2_qbi354#nb zF89D8P0usEo$S9LjxVzk{&J{<(i~;UM7%5#?kEclMndpO)<7wbfp;q&xpt!R@rjmy zzwvm-A5TAsItkUFDoXZpWfOZ*a9{RkQK9iMoS+y|xl6u6DqNm4Zn6JP>NfC(@GCcp%k z025#WOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k z025#WOn?b60Vco%m;e)C0-qp(*^A=R%u&zy%n4!r^5VKlT_ecdbTtt$e`p;u=!(;Q2|fmiL^{ z)?LQEuhBf@+=dc&wu%N&;=)tWw^8EmRM8YlS`+Cq%;WWo!_&oQR`&=|Np&}8XNy%n zU#YabZk}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5^dLc&m`vj5tcjmDkHA+CV~Az+T86mSeilO% zXNl>4bQnwEXSfeb(R+JzW5DQ4nugwE1Vf0OhqorgTKDY?QSLmzA*y|s{N)(eENR97m9a@)OYIXJNFCKNue)*O9w8SHCYNb84huM zj-&2!)D_47VXr@Yr(g;z{3g9-KapIsvrob|?v!ay%tHc+%pIBu6^k zv|wp0X^Mik+JAHH@7MS5HqN)@{ia)#kG=k0 z*Hre~mo6Rhw6y2U9((!N(8)i&`rOV_TfVnc`%~E+e|YCtM-mgeE working with +*/ +#include +#include + +void greetMe(); +void allOdds(); +void allEvens(); +void allThrees(); +void fizzBuzz(); + +int main() +{ + char select, rerun; + + while (1) { + printf("Select one program:\n"); + printf("- A: greetMe\n"); + printf("- B: allOdds\n"); + printf("- C: allEvens\n"); + printf("- D: allThrees\n"); + printf("- E: fizzBuzz\n"); + printf("Enter selction: "); + scanf("%c", &select); + + select = toupper(select); + + switch (select) { + case 'A': + greetMe(); + break; + case 'B': + allOdds(); + break; + case 'C': + allEvens(); + break; + case 'D': + allThrees(); + break; + case 'E': + fizzBuzz(); + break; + } + while (getchar() != '\n'); + + printf("\nRun another? (y/n): "); + scanf("%c", &rerun); + + rerun = tolower(rerun); + + if (rerun == 'n') { + break; + } + while (getchar() != '\n'); + + + } + + return 0; +} + +void greetMe(){ + printf("This function will show \"Welcome!\" many times as you request.\n"); + + int times; + + printf("Enter the number of times you want to show welcome: \n"); + scanf("%d", ×); + + for (int i = 0; i < times; i++) { + printf("Welcome!\n"); + } + + +} +void allOdds(){ + printf("\nThis function print all odds in [0, 10]\n"); + + + for (int i = 0; i <= 10; i++) { + if (i % 2) { + printf("%d\n", i); + } + } + +} +void allEvens(){ + printf("\nThis function print all evens in [0, 10]\n"); + + for (int i = 0; i <= 10; i++) { + if (!(i % 2)) { + printf("%d\n", i); + } + } + +} + +void allThrees(){ + printf("\nThis function print all mutiple of 3 in [0, 10]\n"); + + for (int i = 0; i <=10; i++) { + if (!(i % 3)) { + printf("%d\n", i); + } + } + +} +void fizzBuzz(){ + printf("\nThis function print numbers 1 to 30, but 'fizz' for multiples of 3, 'buzz' for multiples \ + of 5 and 'fizzbuzz' for multiples of both 3 and 5.\n"); + + for (int i = 1; i <= 30; i++) { + + if (!(i % 3) && !(i % 5) ) { + printf("fizzbuzz\n"); + } else if (!(i % 3) ) { + printf("fizz\n"); + } else if (!(i % 5) ) { + printf("buzz\n"); + } else { + printf("%d\n", i); + } + + + } + +} +