Commit 670a0c65 authored by Jesse Eubanks's avatar Jesse Eubanks
Browse files

editing week14.

parent 8d3bfac2
Pipeline #237434 passed with stage
in 26 seconds
const int RLED = 1;
const int GLED = 2;
char comm;
void setup() {
Serial.begin(9600);
pinMode(RLED,OUTPUT);
pinMode(GLED,OUTPUT);
}
void loop() {
if (Serial.available() > 0){
comm = Serial.read();
if (comm == 'A'){
digitalWrite(RLED,HIGH);
delay(100);
} else if (comm =='B'){
digitalWrite(RLED,LOW);
delay(100);
} else if (comm =='C'){
digitalWrite(GLED,HIGH);
delay(100);
} else if (comm =='D'){
digitalWrite(GLED,LOW);
delay(100);
}
}
}
import serial
import tkinter as tk
import time
port = serial.Serial('COM3',9600)
def ronhandler():
port.write(b'A')
def roffhandler():
port.write(b'B')
def gonhandler():
port.write(b'C')
def goffhandler():
port.write(b'D')
def allonhandler():
port.write(b'A')
time.sleep(0.05)
port.write(b'C')
def alloffhandler():
port.write(b'B')
time.sleep(0.05)
port.write(b'D')
window = tk.Tk()
window.geometry("500x200")
ronbutton = tk.Button(text="RED ON", command = ronhandler)
ronbutton.config(width=10,height=5,bg='red')
ronbutton.pack(side=tk.LEFT, padx=10, pady=5)
roffbutton = tk.Button(text="RED OFF", command = roffhandler)
roffbutton.config(width=10,height=5,bg='red')
roffbutton.pack(side=tk.LEFT, padx=10, pady=5)
goffbutton = tk.Button(text="GREEN OFF", command = goffhandler)
goffbutton.config(width=10,height=5,bg='green2')
goffbutton.pack(side=tk.RIGHT, padx=10, pady=5)
gonbutton = tk.Button(text="GREEN ON", command = gonhandler)
gonbutton.config(width=10,height=5,bg='green2')
gonbutton.pack(side=tk.RIGHT, padx=10, pady=5)
allonbutton = tk.Button(text="ALL ON", command = allonhandler)
allonbutton.config(width=7,height=2,bg='yellow')
allonbutton.pack(side=tk.BOTTOM, padx=10, pady=5)
alloffbutton = tk.Button(text="ALL OFF", command = alloffhandler)
alloffbutton.config(width=7,height=2,bg='yellow')
alloffbutton.pack(side=tk.BOTTOM, padx=10, pady=5)
window.mainloop()
\ No newline at end of file
char message;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LED_BUILTIN,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0){
message = Serial.read();
if (message == '1'){
digitalWrite(LED_BUILTIN,HIGH);
delay(100);
} else if (message =='0'){
digitalWrite(LED_BUILTIN,LOW);
delay(100);
}
}
}
import serial
import tkinter as tk
# setting up port
# port = serial.Serial('COM8', 9600) #####
# test LED
# port.write(b'0')
# port.write(b'1')
"""
onhandler:
turns on led
"""
def onhandler():
port.write(b'1')
"""
offhandler:
turns off led
"""
def offhandler():
port.write(b'0')
# create window
window = tk.Tk() # add arguments to adjust window
# create on button
onbutton = tk.Button(text="ON") # add arguments to adjust button
# onbutton = tk.Button(text="ON", command = onhandler) # add arguments to adjust button
onbutton.pack() # puts button on screen
# create off button
offbutton = tk.Button(text="OFF") # add arguments to adjust button
# offbutton = tk.Button(text="OFF", command = offhandler) # add arguments to adjust button
offbutton.pack() # puts button on screen
window.mainloop()
\ No newline at end of file
......@@ -124,7 +124,7 @@ p.agreement {
<h1>Group Work</h1>
<div class="img-with-text">
<img src="Images\network1.jpg" class="image" width="60%">
<img src="Images\network1.JPG" class="image" width="60%">
<i>Equation for spindal speed</i>
</div>
......
......@@ -114,23 +114,93 @@ p.agreement {
<h1><u>Week 14: Interface and Application Programming</u></h1>
<p>In this week for Interface and Application Programming we had a couple of tasks
ahead of us. As a group we set out to compare as many tool options as possible and
for our individual assignment we needed to write an application that interfaces a
user with a device that I made.</p>
<h1>Group Work</h1>
<p>For our group assignment we decided to look into different tool options that we could
have used during this week. The ones that we researched included:</p>
<ul>
<li>Processing</li>
<li>MIT App Inventor</li>
<li>wxPython</li>
<li>MATLAB GUI</li>
<li>Kivy</li>
</ul>
<p>
For this week most of the students in the lab used tkinder to create their individual
assignments. This is what we were demoed to use in the lab and it seemed pretty intuitive
so I continued to use it. This also worked out for me as I have a good amount of experience
in python. I also contemplated using Matlab GUI as I have a lot of experience with Matlab as well.
</p>
<div class="img-with-text">
<img src="Images\interfaceg1.JPG" class="image" width="60%">
<i>Equation for spindal speed</i>
</div>
<p>The spread sheet for our group work can be found
<a href="https://docs.google.com/spreadsheets/d/13yJ5VkVf_Ql9TWEaw3I6c1QM3CxGGQFTvyBFQvlcEPo/edit#gid=0">HERE</a>.</p>
<p><br></p>
<p>When we first tried to use tkinder, we decided to test it out in a python shell in order to get comfortable with the commands.
to open a python shell we can simply type the following in the command window</p>
<p class="text-box">py</p>
<p>The first thing we can do next is type</p>
<p class="text-box">import serial</p>
<p>And</p>
<p class="text-box">import tkinter as tk</p>
<p>This will allow us to import the python libraires that we will need in order to
create the interface that we want</p>
<p>Next we will define a couple of functions that we want to activate</p>
<p class="text-box">def onhandler():<br>. . . port.write(b'1')</p>
<p>And,</p>
<p class="text-box">def offhandler():<br>. . . port.write(b'0')</p>
<p>to be able to activate the commands we will need to make buttons so we can
actually interact with them. But before we can have buttons, we need to make a window</p>
<p class="text-box">window = tk.Tk()</p>
<p>To create button we can type out,</p>
<p class="text-box">onbutton = tk.Button(text="ON", command = onhandler)</p>
<p>And to actually place it on the window we type,</p>
<p class="text-box">onbutton.pack()</p>
<div class="img-with-text">
<img src="Images\interface1.JPG" class="image" width="60%">
<i>Equation for spindal speed</i>
</div>
<p>below is the result that comes from typing out all of the above commands.</p>
<div class="img-with-text">
<img src="Images\interface2.JPG" class="image" width="20%">
<i>Equation for spindal speed</i>
</div>
<p>When creating the individual assignment, we will actually want to write out and save
what we typed out. You can see that id did that in the Wing IDE for python down below.</p>
<div class="img-with-text">
<img src="Images\interfaceg3.JPG" class="image" width="60%">
<i>Equation for spindal speed</i>
......@@ -138,27 +208,86 @@ p.agreement {
<h1>Individual Assignment</h1>
<p>Because of some boards that I created not working much anymore I decided to create
an interface that would turn on and off some LEDs for my board from the electronics design week.</p>
<div class="img-with-text">
<img src="Images\interface3.JPG" class="image" width="60%">
<i>Equation for spindal speed</i>
</div>
<p>During the lab we basically only scratched the surface of what was possible in tkinder. One of the first things
that I wanted to do was create more space for my interface. To do this I increase my window size by typing,</p>
<p class="text-box">window.geometry("500x200")</p>
<p>This command changed my window to be about 500 x 200 pixels</p>
<p>Also, since I wanted four buttons in total, two to turn on and off the green LED, two to
turn on and off the red LED, and two to turn on ad off all LEDs. The only command that was a little different
was the ones that involved all the LEDs. First I imported the time library so that I could delay so that it could
print 'A' then 'C' into the serial instead of 'AC'</p>
<p class="text-box">import time</p>
<p>The new command I created looked like</p>
<p class="text-box">def allonhandler():<br>
. . . port.write(b'A')<br>
. . . time.sleep(0.05)<br>
. . . port.write(b'C')</p>
<div class="img-with-text">
<img src="Images\interface4.JPG" class="image" width="60%">
<i>Equation for spindal speed</i>
</div>
<p>Next I created a series of arguments to adjust exactly how I wanted my buttons to work. First I still had this
command</p>
<p class="text-box">ronbutton = tk.Button(text="RED ON", command = ronhandler)</p>
<p>Here I'm making the button but to actually edit some of its features I typed out</p>
<p class="text-box">ronbutton.config(width=10,height=5,bg='red')</p>
<p>This changed the size of the button as well as the color.</p>
<p>This time, when I pack the button, I can type it out like this,</p>
<p class="text-box">ronbutton.pack(side=tk.LEFT, padx=10, pady=5)</p>
<p>The added arguments inside the pack command help me to position the button inside of the
window.</p>
<div class="img-with-text">
<img src="Images\interface5.JPG" class="image" width="60%">
<i>Equation for spindal speed</i>
</div>
<p>All in all, this is what my design for my interface ended up looking like. Below
you can see a video of it working in real time.</p>
<video class="image" controls autoplay loop>
<source src="interface.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<h1>Attachments</h1>
Lab Files:
<ul>
<li><p><a href="lab_5.6.ino">Arduino File</a></p></li>
<li><p><a href="lab_5.6.py">Python File</a></p></li>
</ul>
Individual Files:
<ul>
<li><a href="interface.ino">Arduino File</a></li>
<li><a href="interface.py">Python File</a></li>
</ul>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment