<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kyle Trahan</title>
    <description>The latest articles on DEV Community by Kyle Trahan (@ktrahan2).</description>
    <link>https://dev.to/ktrahan2</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F451997%2F2970ec2c-9529-4ea6-a135-af5290afbcb7.jpg</url>
      <title>DEV Community: Kyle Trahan</title>
      <link>https://dev.to/ktrahan2</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ktrahan2"/>
    <language>en</language>
    <item>
      <title>Hacking a SNES Controller</title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Fri, 12 Mar 2021 16:31:09 +0000</pubDate>
      <link>https://dev.to/ktrahan2/hacking-a-snes-controller-mg3</link>
      <guid>https://dev.to/ktrahan2/hacking-a-snes-controller-mg3</guid>
      <description>&lt;p&gt;I reached the end of the Arduino tutorial book the other day and finally got a look at what it takes to hack into an existing electronic device. Come to find out I don't have to many electronics in my house that my girlfriend was willing to potentially part with. Lucky for me she did have an extra SNES controller that was fit for the job. So I got to work on taking the controller apart. Which was surprisingly easy, and really cool to see that I actually understood, for the most part, what was going on inside. &lt;/p&gt;

&lt;p&gt;My plan was to find a SNES game that had a jump action in the game. My goal was to set up a tilt sensor on my breadboard and wiring that to the jump button on the controller. Making it possibly for me to kind of shake the breadboard in order to cause the character to jump. &lt;/p&gt;

&lt;p&gt;I had some varying levels of success. I got the functionality working but since I don't have a soldering kit and wasn't really willing to ruin the controller, I was left with taping the wires onto the SNES controller. This made short circuiting the SNES button a little shakey as far as when it would actually work, but in the end it did work! It was more about a proof of concept for me. I am now able to hack into existing electronics and that was a very rewarding feeling. &lt;/p&gt;

&lt;p&gt;The code for this project was really simple. I was able to take the tutorial code and make some tweaks here and there to fit my needs. The big new component for me on this was the optocoupler. Optocouplers are typically used to allow transfer of analog or digital information between circuits while maintaining electrical isolation. Basically it allows you to trigger things on and off without the opportunity for the power from each device overlapping. &lt;/p&gt;

&lt;p&gt;Heres the code for the project if you were interested:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const int optoPin = 2; 
const int switchPin = 8;
int switchState;

void setup() {
  Serial.begin(9600);
  pinMode(optoPin, OUTPUT);
  pinMode(switchPin, INPUT);
}

void loop() {

  switchState = digitalRead(switchPin);
  if ( switchState == 1) {
    digitalWrite(optoPin, HIGH);  
    delay(15); 
    digitalWrite(optoPin, LOW);  
  }

  Serial.println("switchstate:");
  Serial.println(switchState);

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I had a really fun time building this project and am still super excited to continue down the path of microcontrollers. Hope this was a little insightful and have a great day!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Cypress Testing</title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Wed, 10 Mar 2021 21:29:03 +0000</pubDate>
      <link>https://dev.to/ktrahan2/cypress-testing-4da1</link>
      <guid>https://dev.to/ktrahan2/cypress-testing-4da1</guid>
      <description>&lt;p&gt;I have been playing around a little bit with testing lately just so I can have a semi intelligent conversation about it during an interview, just in case. I had used Jest before since I was typically working in React, but recently was re-exploring vanilla JS and decided to use Cypress. &lt;/p&gt;

&lt;p&gt;I'm going to explain a few of the Cypress functions provided that will help you start writing some test. One of the the key functions would be cy.visit. This tells the test what page you are actually wanting to run the follow test on. They give an example url to follow in the docs. So you would write this to start off with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('Is title rendering?', () =&amp;gt; {
  it('checks for the app title', () =&amp;gt; {
    cy.visit('https://example.cypress.io')
  })
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next function would be .contains. If you already know exactly what your title name is then you can find it with .contains. We would just add this line under cy.visit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cy.contains('the name of your title')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets say you don't know what your titles' text contents will be but we do know what its id is. You can use the .get function like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cy.get('#app-title')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will ensure that there is an element on your page that has the id of #app-title. I think this can be useful in determining whether or not something is present on the page. &lt;/p&gt;

&lt;p&gt;These are just some of the really basic functions for Cypress and a good way to get started. There is so much more to them though if you take a little time to dig into the documentation and do a little experimenting! &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Knock Lock</title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Fri, 26 Feb 2021 19:26:36 +0000</pubDate>
      <link>https://dev.to/ktrahan2/knock-lock-49of</link>
      <guid>https://dev.to/ktrahan2/knock-lock-49of</guid>
      <description>&lt;p&gt;Finally hopping back into the Arduino chair after not doing very much with it lately. I found a setup to create a knock lock, which essentially has a button switch that will turn a lock to the closed position. Then using a piezo the lock will open back up according to the specified knock requirements, in this example it's just three knocks that register within the given range of values on the piezo. &lt;/p&gt;

&lt;p&gt;This was one of the more complicated circuit systems I have put together so far, but it just required a little bit more focus. I had a really good time doing it and played with a few different knocking combinations. &lt;/p&gt;

&lt;p&gt;The different components required for this are a servo motor, 3 LEDs (preferably different colors), 1 piezo, 1 button switch, 1 capacitor, and all the wiring/resistors required for each to connect to ground, power, and a pin in the breadboard. &lt;/p&gt;

&lt;p&gt;Before the setup function you will want to declare all of the different variables you are using. It's a lot easier to read through your code when pin7, which is hooked up to the yellow LED, is called something like yellowLED. Here's a list of all the variables I made in order to do this project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;Servo.h&amp;gt;
Servo myServo;

const int piezo = A0;
const int switchPin = 2;
const int yellowLED = 7;
const int greenLED = 9;
const int redLED = 13;

int knockVal;
int switchVal;

const int minKnock = 10;
const int maxKnock = 100;

boolean locked = false;
int numberOfKnocks = 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next up you are going to want to set what all of your pins are actually doing, ie are they an output pin or an input pin. Along with declaring what pin your servo motor is connected to. Heres that code as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void setup() {
  myServo.attach(11);
  pinMode(yellowLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  pinMode(switchPin, INPUT);
  Serial.begin(9600);
  digitalWrite(greenLED, HIGH);
  myServo.write(0);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally we are going to want to describe what happens in our loop function. This will be where all the logic is actually happening in order to control our lock. We will set up an if statement in order to change to the locked position like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if ( locked == false) {
    switchVal = digitalRead(switchPin);
    if (switchVal == HIGH ) {
      locked = true;
      digitalWrite(greenLED, LOW);
      digitalWrite(redLED, HIGH);
      myServo.write(90);
      delay(1000);
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We just check to see that the lock is open, if it is then we check to see if the value of our button switch is HIGH, aka on. After that we make some adjustments to the visual part of the board to let you know that the lock did in fact lock. Turn the green light off and the red light on. Also rotating the servo in order to move the lock into place. &lt;/p&gt;

&lt;p&gt;Next up we set up the functionality to read the incoming knocks from the piezo like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if ( locked == true ) {
    knockVal = analogRead(piezo);
    if ( numberOfKnocks &amp;lt; 3 &amp;amp;&amp;amp; knockVal &amp;gt; 0 ) {
      if ( checkForKnock(knockVal) == true ) {
        numberOfKnocks++;
      }
    }
    if ( numberOfKnocks &amp;gt;= 3 ) {
      locked = false;
      myServo.write(0);
      delay(20);
      digitalWrite(greenLED, HIGH);
      digitalWrite(redLED, LOW);
      numberOfKnocks = 0;
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we check that our locked state is true. If so we will set the knockVal to the value coming in on the piezo. If our current knock count is less than the required amount, 3, and the knockVal is greater than 0, or in other words the piezo registered a sound. Then we will run the function to check if the knock registered in between our min and max knock values. That function looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;boolean checkForKnock(int value) {
  if ( value &amp;gt; minKnock &amp;amp;&amp;amp; value &amp;lt; maxKnock ) {
    digitalWrite(yellowLED, HIGH);
    delay(50);
    digitalWrite(yellowLED, LOW);
    return true; 
  }
  else {
    return false;
  }
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the knock registers between our min and max values then we will increment our knock count. The yellow LED is there to let you know if a knock registers or not by lighting up upon successful knocks. &lt;/p&gt;

&lt;p&gt;Once the knock count reaches the required amount then the lock turns back to false and we turn our servo motor back to its unlocked position. &lt;/p&gt;

&lt;p&gt;This was a bit of a longer winded post then most of my Arduino post, but I feel like this could be implemented in some cool ways. Maybe you want to lock your bedside table or with the right materials your front door! You might want a more secure knock code for your front door though! Hope this was an enjoyable read. Thanks for tuning in and have a great day!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Firebase Cloud Functions</title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Mon, 22 Feb 2021 04:15:46 +0000</pubDate>
      <link>https://dev.to/ktrahan2/firebase-cloud-functions-4ofa</link>
      <guid>https://dev.to/ktrahan2/firebase-cloud-functions-4ofa</guid>
      <description>&lt;p&gt;Cloud functions are great way to operate a serverless backend. They are functions you can create with JS or typescript and then they are stored on google cloud to preform actions based off HTTP request or firebase features. They are pretty easy to setup, once you have everything setup its just a specific call to create a cloud function. Looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const functions = require("firebase-functions");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exports.functionName = functions.https.onRequest((request, response) =&amp;gt; {})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you create your function and set up what ever logic you want to happen, you'll then want to deploy your function up to firebase. As long as there are no errors in your code your function will now be hosted on google cloud/firebase. You'll be provided with a url that you can now send request to in order to preform the function you created. &lt;/p&gt;

&lt;p&gt;Typically these cloud functions are going to be used for firebase features like authentication or google services like cloud storage. Here is an example function that will grab a specific user from our firestore collection of users.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exports.getUser = functions.https.onRequest((request, response) =&amp;gt; { 
    cors(request, response, () =&amp;gt; { 

        const userId = request.body.userId;

        const userRef = db.collection('users').doc(userId);
        userRef.get()
        .then(snapshot =&amp;gt; {
            if (snapshot.exists) {
                response.send(snapshot.data())
            } else {
                response.send("User not found")
            }
        }).catch(error =&amp;gt; response.send({errors: error}));
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;onRequest() allows you to use the cloud functions you create with http request. Giving us access to both the request and response. The request can be used to receive information that you might use in order to find specific data entry, for instance in the example above we grab the userId out of the request body. Then we are able to send back whatever information is needed back through the response with response.send(). &lt;/p&gt;

&lt;p&gt;These are the basics to firebase cloud functions. They can be really useful for working with a firebase project. There is very little maintenance required after creating them. It will take a little time to get use to working with them but once you do it seems to be pretty smooth sailing. Hope you were able to take away something from this and I hope you have a great day!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Cloud Firestore</title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Sun, 14 Feb 2021 17:49:24 +0000</pubDate>
      <link>https://dev.to/ktrahan2/cloud-firestore-1di6</link>
      <guid>https://dev.to/ktrahan2/cloud-firestore-1di6</guid>
      <description>&lt;p&gt;I recently joined a group to participate in a hackathon. We decided to do our backend in node and to put Firebase's Firestore to use. This was my first real project working with either of these technologies so it has been a very firehose of information kind of week. I wanted to share a few things about Firestore that I learned as a result. &lt;/p&gt;

&lt;p&gt;Starting off with what Firestore can do for you. Firestore is essentially a scalable NoSQL database, which is used via the Cloud. It allows your data to stay in sync over multiple different platforms. &lt;/p&gt;

&lt;p&gt;One of the most helpful parts of using Firestore is that you can use the prebuilt firebase authentication to handle your users sign in information with very little hassle. We went through a few hiccups along the way but eventually were able to get a functioning authentication system set up!&lt;/p&gt;

&lt;p&gt;From here we needed to start collecting information about our users. We created an application that would eliminate the need for any paper whenever it comes time to renew your license at the DMV. With our app DMVeasy you are able to fill out all the information that is required for any form for this process and then it is automatically generated into pdf format. Also you are able to upload images of all the different requirements such as a copy of your passport, social security card etc. Thus eliminated the waste that results from making photocopies of all of these things. &lt;/p&gt;

&lt;p&gt;This brings me into actually using the database. It was a very interesting process trying to learn, which I actually really enjoyed. So you start off making a collection, which is just a container that will hold documents that have similar attributes in them. So for example we have a collection of users, and within that collection there are a bunch of documents identified by a unique key. Then inside that document is where we hold all of our information retaining to that specific user. It works very similarly to creating a table and assigning what columns will be inside that container. One of the really big differences is that in a table all of the data entries will have the same columns. In a collection you can actually set each document in that collection to have whatever attributes you want. Which sounds a bit overwhelming in that your database could fairly quickly become very disorganized, but with a little bit of validating we feel like we are sitting in a pretty good place. &lt;/p&gt;

&lt;p&gt;I wanted to talk a little bit about one of the functions I created while going through the project. It has to do with the ability to update a users information. As we only had about 10 days to do the hackathon we were pretty limited on time. This was one place I feel like working with Firestore really thrived. Since I was mostly focused on the backend side of the project and my partners were focused primarily on getting the pdf functionality to work. I was unsure exactly what information the update function would be receiving in the request. So I wanted to create a dynamic solution that could work for any key in the requests body, until we finalized what exactly would be sent back. Heres my solution below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        const userInformation = {};

        for ( let info in request.body ) {
            if ( info !== "userId") {
                userInformation[info] = request.body[info];
            };
        };

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I basically just looped through the request.body object and created a new object that would make key value pairs that match whatever was sent back in the request. I was happy with my solution in order to help us continuing to move forward without getting bogged down by exactly what information we would end up saving in our database. Since Firestore allows you to be so dynamic with your collection information, the two paired very well together. Overall I had a lot of fun working on this project. I might go into a little more detail with the auth process in my next blog. Thanks for taking the time to read this and have a great day!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Redux Hooks</title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Sat, 06 Feb 2021 17:53:48 +0000</pubDate>
      <link>https://dev.to/ktrahan2/redux-hooks-19gb</link>
      <guid>https://dev.to/ktrahan2/redux-hooks-19gb</guid>
      <description>&lt;p&gt;Recently I decided I would take my first React-Redux project and refactor it to see how far I have progressed since being in Flatiron School. When I opened up my code it was a bit overwhelming to see how disorganized it felt considering how happy I was with it when I originally wrote it. I was using class components and passing my Redux store state around with the connect wrapper. I figured I would take a shot at refactoring to use hooks everywhere instead. This required transitioning all of my class components into functional components. This was no small task but I was eventually able to complete it. &lt;/p&gt;

&lt;p&gt;Funnily enough I actually stored all of my reducers inside of my index.js file, don't ask me why. So I also went through the process of reorganizing my file structure so that it would be easier to come back to this project and not feel so lost. &lt;/p&gt;

&lt;p&gt;Then I moved on to learning about the different hooks Redux uses. The two I will be focusing on are useSelector and useDispatch. It might just be a sign of the progress I have made since first learning Redux, but I found using hooks was less complicated then when I originally learned how to use the connect wrapper. So here we go, first up is useSelector, this is the equivalent of mapStateToProps. Its very simple to use and it will give you access to your store state. It looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const thingIWant = useSelector( state =&amp;gt; state.thePieceOfStateIWant)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The useSelector function is very smart in that whenever a new dispatch is sent it won't automatically re-render. It will check to see if the value has changed and re-render only if the value has changed. &lt;/p&gt;

&lt;p&gt;The other hook I wanted to mention was useDispatch. It is equivalent to mapDispatchToProps. This hook will return a reference to the dispatch function. It allows you to send a dispatch to the store and update your state there based on the action.type. Its fairly simple to put into action as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const dispatch = useDispatch()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you can use this variable to send dispatches to your store like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dispatch({ type: "WHATEVERTYPE", payload: infoToUpdate})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thats all there is to it, you can set up your reducers the same way you normally would using connect but now you can type out less code in order to gain access to and update your store. I'm really enjoying the process of updating my project and seeing how far I have come. I am still working through quite a lot of things and can't wait to see where the project ends up. Have a great day!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>DC motor Arduino</title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Fri, 29 Jan 2021 16:23:10 +0000</pubDate>
      <link>https://dev.to/ktrahan2/dc-motor-arduino-3be4</link>
      <guid>https://dev.to/ktrahan2/dc-motor-arduino-3be4</guid>
      <description>&lt;p&gt;Last week I got some distance sensors to start working on the problem of "what happens when my robot runs into an obstacle". I got a basic sensor working that printed out the distances that were being recorded. This week I took it a small step forward and added a DC motor to the mix.&lt;/p&gt;

&lt;p&gt;I worked out a pretty simple solution for now that will cause a motor to turn on based off something being within 5cm of the sensor. Since I already had the code from before to determine the distance. It was as simple as adding the pin the motor is connected to and then making a conditional statement about what distance the motor should turn on/off at. &lt;/p&gt;

&lt;p&gt;First we declare our variable for the pin we are connected to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int motorPin = 6;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks like this inside the setup():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pinMode(motorPin, OUTPUT);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and this in the loop():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if ( distance &amp;lt;= 5 ) {
    digitalWrite( motorPin, HIGH ); 
 } else {
    digitalWrite( motorPin, LOW );
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After completing that test I noticed that the motor seemed to be going really fast and that didn't seem like a very good way to turn around. So I did a little bit more digging and found that you can control the speed of the motor. So I made a small tweak to the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if ( distance &amp;lt;= 5 ) {
   analogWrite( motorPin, 100 ); 
} else {
   digitalWrite( motorPin, LOW );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will just set the speed of the motor to a specific speed instead of running at its fastest speed by default.&lt;/p&gt;

&lt;p&gt;On a bigger scale I would have to do some programming to turn one set of wheels on in one direction while the other side goes in the opposite direction. At least as of now that will be my plan, but I am still contemplating between making a four or three wheeled little robot friend! &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Arduino Distance Sensor</title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Fri, 22 Jan 2021 20:42:04 +0000</pubDate>
      <link>https://dev.to/ktrahan2/arduino-distance-sensor-1iio</link>
      <guid>https://dev.to/ktrahan2/arduino-distance-sensor-1iio</guid>
      <description>&lt;p&gt;I finally got my Arduino distance sensors in the mail. This is my first time expanding my knowledge outside of the beginners tutorial book. As I have been working through the tutorial book I was trying to think of what I wanted my first real project to be. As an end goal I want to try and make a robot from scratch that will essentially act like a roomba, but rather than being a floor cleaning slave, my robot will just wonder around the house aimlessly contemplating the finer things in life. Like which walls to not run into. I figured my first step would be figuring out how to give my robot eyes. This landed me on getting a few Ultrasonic Sensors to start playing around with. These sensors work kind of like a bat or a dolphin using echo location in order to determine how far something is from its sensors. The basic goal would be to keep the robot from running into walls by setting a designated minimum distance in which to tell the robot to turn. &lt;/p&gt;

&lt;p&gt;I started off really simple and just set up the sensor on my bread board and moved different objects in front of it to test the sensors reach. I was able to get to about 10 feet away before it started to get a little wonky. So this should work just fine at a small distance of an inch or two. The coding for it was pretty simple. Ill go over that a little more below.&lt;/p&gt;

&lt;p&gt;I'll skip all the boring parts like hooking up the power and the ground. The two new pins for me are a trigger pin and an echo pin. Basically the trigger pin will go from off to on to off again. This basically sends off a sonic burst that will travel until it hits something and then it returns back to the sensor. Then the echo pin works its magic by receiving that burst and translating it into the computer to let us know how long it took to travel. There is a little bit of math that gets done with the duration in order to figure out just how far we traveled. You take your duration and multiple that by the speed of sound or 340 m/s ( .034 cm/microsecond) and then divide that by two, since the sound is traveling there and back it actually gives us double the duration we need. The code below will go over how that happened:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void loop() {
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin, LOW);
  duration = pulseIn(echoPin, HIGH);

    distance = duration * .034 / 2;

    Serial.print("Distance: ");
    Serial.print(distance);
    Serial.println(" cm");

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Im very excited to get the next piece of my robot puzzle together. I will probably start to get more into the motors and figuring out how to make the wheels work. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Learning to Code for an Adruino </title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Sat, 16 Jan 2021 16:29:28 +0000</pubDate>
      <link>https://dev.to/ktrahan2/learning-to-code-for-an-adruino-3j7i</link>
      <guid>https://dev.to/ktrahan2/learning-to-code-for-an-adruino-3j7i</guid>
      <description>&lt;p&gt;After buying my Arduino starter kit I start diving into it and realized that the coding part of it was actually really simple. From my last blog post I talked about the musical keyboard I made. Now I want to go into a little more detail about the actual code behind the scenes. &lt;/p&gt;

&lt;p&gt;So most arduino projects consist of two different functions. You have your setup(), which is run once when the program starts and you have your loop() that continues to run based off the conditions you have set within. Other than that its pretty simple straight forward coding. You can declare some variables before getting started to store different sets of data. &lt;/p&gt;

&lt;p&gt;The main variable I needed for this project was just an array of integers. Creating that looks like so:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;int notes[] = { 262, 294, 330, 349 }&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Pretty simple really, if you haven't worked with a typed language. This is basically just saying I have an array called notes made up of integers. &lt;/p&gt;

&lt;p&gt;Next up we have the setup() function, which was really simple for this project. It looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; void setup() {

  Serial.begin(9600);

} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Serial is a port object, we are telling it to start, and to work at a speed of 9600 bits per second (baud). This basically just opens up a serial port, and sets the data rate to 9600 bps. What this really means is that now whenever I press buttons on the keyboard I will receive the output data so that I can see how much power is coming through each button. Then I can use that information to set what frequency should play based on the amount of power coming through. It just allows for some fine tuning. The other part of this functionality is kept within the loop(). &lt;/p&gt;

&lt;p&gt;Next up we have the loop() function. Also pretty simple for this project it just has a few if else statements to determine what note should be played for a range of frequencies. In here we are using Serial.print in order to print out those values we need in order to set our ranges to determine which frequency should be played.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void loop() {

  int keyVal = analogRead(A0);
  Serial.print(keyVal);

   if ( keyVal == 1023 ) {
    tone( 8, notes[0] );
   } else if ( keyVal &amp;gt;= 990 &amp;amp;&amp;amp; keyVal &amp;lt;= 1010 ) {
    tone( 8, notes[1] );
   } else if ( keyVal &amp;gt;= 505 &amp;amp;&amp;amp; keyVal &amp;lt;= 515 ) {
    tone( 8, notes[2] );
   } else if ( keyVal &amp;gt;= 5 &amp;amp;&amp;amp; keyVal &amp;lt;= 10 ) {
    tone( 8, notes[3] );
   } else {
    noTone(8);
   }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In here we are setting our keyVal to be equal to the input that is being read by the A0 pin on our Arduino board. This will basically take a reading of how much power is passing through whenever you hit the button. Each button is wired up with a different level resistor therefore they should all be transferring different levels of power. Then its as simple as saying if its between these two power levels I want you to tone(8), aka play this note through our piezo which is connected to pin 8 on the Arduino board. Which we then grab a different frequency from the notes[] we made earlier. Its important to remember to set everything else to just play noTone() otherwise you'll have a frequency playing all the time!&lt;/p&gt;

&lt;p&gt;Thats for taking the time to read this and stay tuned for future projects. Have a great day!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Intro to Arduino</title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Fri, 08 Jan 2021 16:17:21 +0000</pubDate>
      <link>https://dev.to/ktrahan2/intro-to-arduino-4pfh</link>
      <guid>https://dev.to/ktrahan2/intro-to-arduino-4pfh</guid>
      <description>&lt;p&gt;After graduating from Flatiron School I started exploring the idea of getting into robotics. I wasn't really sure where to start so I went down some rabbit holes and landed on getting the Arduino starter kit. Its a really awesome kit and comes with all the basic components to get you started. The best part about the kit is that it comes with a tutorial book. The book does a really good job at slowly introducing you to the different components through different circuit builds. &lt;/p&gt;

&lt;p&gt;Theres also some coding that goes into the projects which is also provided so you can learn some C++ along the way. The programming language they introduce you too is called Arduino language which is essentially a framework built on top of C++. It's been really interesting to work with, the biggest adjustment for me so far is remember the ";" is required at the end of a line, haha. &lt;/p&gt;

&lt;p&gt;One of my favorite projects I have worked on so far is a musical keyboard. They introduce a new concept called a resistor ladder. Which is essentially a way to connect multiple switches to the same analog input. &lt;/p&gt;

&lt;p&gt;The main components to this build are buttons, a piezo, resistors, and a few wires. The piezo is the device that emits the different frequencies. The different frequencies are determined by the amount of voltage that is able to go through the button whenever you press it. The way the voltage is controlled is using different levels of resistors. So the code for this is pretty simple. You basically want to write a bunch of conditional statements to emit a specific frequency depending on a range of voltage values. &lt;/p&gt;

&lt;p&gt;If you are interested in what the actual code looks like stay tuned for next week. Im going to get a little more in depth on what goes into coding an Arduino project. I am thoroughly enjoying the ride that I have gotten on and can't wait to see what I am able to produce in the future. Right now my end goal is to make a little droid friend that can roam around my apartment just living its best life! Thanks for taking the time to read this. Hope you have a great day! &lt;/p&gt;

</description>
      <category>arduino</category>
    </item>
    <item>
      <title>Mutating vs Non-Mutating JS Arrays</title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Wed, 30 Dec 2020 17:00:04 +0000</pubDate>
      <link>https://dev.to/ktrahan2/mutating-vs-non-mutating-js-arrays-o36</link>
      <guid>https://dev.to/ktrahan2/mutating-vs-non-mutating-js-arrays-o36</guid>
      <description>&lt;p&gt;In my last blog post I talked about some mutating methods to manipulate your JS arrays. Such as .push and .unshift. This week I wanted to talk about different ways you can manipulate a JS array using non-mutating methods. &lt;/p&gt;

&lt;p&gt;There are two key methods used for adding new items to an array without mutating the original array. They allow you to do something similar to .push/.unshift. The first being the .concat() method. The syntax is very similar to the others. &lt;br&gt;
Lets say we had an array that looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let numbersArray = [ 1, 2 ,3 ]&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 and we wanted to add 4 to that array without mutating the original. You could use concat like so:&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;let numbersArray2 = numbersArray.concat(4)&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 The original numbersArray would still show as [ 1, 2, 3 ] while our new array would show the 4 added in. &lt;/p&gt;

&lt;p&gt;Another way to go about adding elements into an array is to use JS's spread operator. The syntax looks like this:&lt;/p&gt;

&lt;p&gt;To add to the end:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let numbersArray2 = [ ...numbersArray, 4 ]&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 or to add to the beginning:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let numbersArray2 = [ 4, ...numbersArray ]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This takes all of the values from numbersArray and creates a new array with the addition of the number 4 either at the end for the first example or the beginning for the second example. &lt;/p&gt;

&lt;p&gt;Let's move on to ways to remove elements from an array without mutating the original. These methods are going to do something similar to .pop/.shift. You could use a method called .filter. This method will sort through an array and create a new one based off of a condition you set. It looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;numbersArray2 = numbersArray.filter( value =&amp;gt; value !== 3  )&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 numbersArray2 would only include [ 1, 2 ] however the original array would remain unchanged. &lt;/p&gt;

&lt;p&gt;Another method you can use is called slice. In this method you pass in the parameters of where you want to start your new array and where you want it to end. If you leave the second number out then slice will just go to the last value of the array. Using slice would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;numbersArray2 = numbersArray.slice(0, 2)&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 So we are saying that we want our numbersArray2 to start at the 0th index and finish on the 1st index. The ending point you pass in to slice is non inclusive, meaning it won't be included in your array. So our numbersArray2 would look like [ 1, 2 ]. &lt;/p&gt;

&lt;p&gt;I hope this was helpful in understanding a few non-mutating functions with JS arrays. Stay tuned next week I will be going over some functions that iterate over JS arrays. We already saw one in this blog, .filter!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Javascript Array Properties and Methods</title>
      <dc:creator>Kyle Trahan</dc:creator>
      <pubDate>Wed, 23 Dec 2020 16:46:22 +0000</pubDate>
      <link>https://dev.to/ktrahan2/javascript-array-properties-and-methods-1c50</link>
      <guid>https://dev.to/ktrahan2/javascript-array-properties-and-methods-1c50</guid>
      <description>&lt;p&gt;I'll be going over the length/size property and a couple methods involving removing/adding an index/indexes to an array. &lt;/p&gt;

&lt;p&gt;One of the most commonly used properties of a Javascript array is .length. This property when called on an array will return to you the amount of items inside your list. This is extremely helpful when it comes time to iterate through your list. It is commonly used to set the condition upon which your loop will stop running. &lt;/p&gt;

&lt;p&gt;You can also use the length method to clear the array out. If you set the array.length = 0. You can also set the value of your index by doing array[index] = value. This can be dangerous however because you could end up leaving empty values on all the indexes between the one you are setting and the last one you set. It's one of the downfalls of arrays being so versatile. It's better to use the built in methods for arrays rather than treating them like a normal Javascript Object. &lt;/p&gt;

&lt;p&gt;This leads me to the first few methods I am going to discuss. Those being .push(), .pop(), .shift(), and .unshift(). First we will touch on .push() and .unshift() as they both add an item to an array. &lt;/p&gt;

&lt;p&gt;The difference between .push() and .unshift() is rather small. They are invoked in the same way by calling the function on an array and then passing them the value/s that you want to add to your array. The biggest difference is that .unshift() will add the value to the beginning of your array and .push() will add the value to the end of the array. &lt;/p&gt;

&lt;p&gt;The other two methods .pop(), and .shift() are very similar to their counter parts. Rather than add values to an array they will remove items from the array. With .pop() removing the last element and .shift() removing the first element. &lt;/p&gt;

&lt;p&gt;These are some of the most commonly used methods for arrays whenever you first start learning about Javascript arrays. They all are considered to be mutating the array, which isn't always what you want to do! If you want to learn more about what I mean by mutating and ways to change your array non-mutating I will be doing another blog next week about that! &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
