You follow section 3.1 of your Arduino workshop and set up your breadboard and control the Toggle switch using if-statement.

Learning Goal: I’m working on a computer science project and need a sample draft to help me learn.

This LAB relates to Module 5 and has three parts:

1- You follow section 3.1 of your Arduino workshop and set up your breadboard and control the Toggle switch using if-statement. (50 points)

2- Follow section 3.2 of your Arduino workshop, set up your breadboard, and write your code to change the structure of your code using While-loop. (50 points)

3- For the last part follow section 3.3 and use for-loop to control the flow of your program for your Arduino, using the Serial Monitor to display the data. (50 points)

Chapter 3: Decision Making and Using Logic – Part 2

3.0 CHAPTER OVERVIEW

In Module 5 learned about:


3.4 USING ‘SWITCH’ CASES

In this section, we’ll dive into using ‘switch’ cases to implement comparative lists and outcomes.

(447) Arduino Workshop – Chapter Three – SWITCH CASE Statements – YouTubeLinks to an external site.

Source Code for ‘Potentiometer Switch Case’

// pin definitions
int potPin = A0;

// declare global variables
int lastPotValue;

void setup() {
  // set pin modes
  pinMode(potPin, INPUT);
  //initialise Serial port
  Serial.begin(9600);
}

void loop() {
  // read potPin and divide by 255 to give 5 possible readings
  int potValue = analogRead(potPin) / 255;
  
  // if something has changed since last value
  if(potValue != lastPotValue)
  {
    // enter switch case
    switch(potValue)
    {
      case 0:
        Serial.println("Very Low");
        break;
      case 1:
        Serial.println("Low");
        break;
      case 2:
        Serial.println("Moderate");
        break;
      case 3:
        Serial.println("High");
        break;
      case 4:
        Serial.println("Extreme");
        break;
      default:
        Serial.println("error!");
        break;
    }
    lastPotValue = potValue;
  }
}

Wiring Diagram for ‘Potentiometer Switch Case’

pot_bb.webp


3.5 USING MATHS

In this section, we’ll look at how to use different mathematic functions and methods in Arduino.

(447) Arduino Workshop – Chapter Three – SWITCH CASE Statements – YouTubeLinks to an external site.

For example for ‘Maths Functions’

x = y + 3;
x = y - 7;
x = y * 6;
x = y / 4;

3.6 CREATING FUNCTIONS

In this section, we’ll be learning about using and creating your own functions to write modular, reusable code.

(447) Arduino Workshop – Chapter Three – Creating Functions – YouTubeLinks to an external site.

Source Code for ‘Hypotenuse Calculator’

*Update: I’ve updated the sketch for the hypotenuse calculator which is reflected in the code below. It provides rejection for non-integer values and some extra feedback.

void setup() {
  //initialise Serial port
  Serial.begin(9600);
}

void loop() {
  int a;
  int b;
  float result;

  //print instructions, and wait until there is something in the serial buffer
  Serial.print("Enter a side value: ");
  while(!Serial.available());
  a = readSerial();
    if(a == 0)
    {
      return;
    }
  Serial.print("Enter the other side value: ");
  while(!Serial.available());
  b = readSerial();
    if(b == 0)
    {
      return;
    }
  findSide(a,b);
  
  Serial.println();
}

//readSerial takes the next integer in the Serial buffer, clears the buffer, then returns it
int readSerial()
{
  int i = Serial.parseInt();

  //checks if the received value is a valid integer
  if(i < 1 || (i%1 != 0))
  {
    Serial.println("That isn't a valid integer");
    return 0;
  }
  Serial.println(i);
  Serial.parseInt();
  return i;
}

void findSide(int x, int y)
{
  //calculate C squared by A squared + B squared
  float hypotenuse = sqrt(x*x + y*y);
  
  //print out the result
  Serial.print("Hypotenuse = ");
  Serial.println(hypotenuse);
}

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
error: Content is protected !!