The Arduino Platform and C Programming, week (1-4) All Quiz Answers with Assignments.

The Arduino Platform and C Programming

week 1 Assignment :







week 2 Assignment :

PROMPT

Write a program in C that computes and prints out the first six digits in the Fibonacci sequence. Look up the definition of the Fibonacci sequence if you don't know it. The first two numbers in the sequence are 0 and 1, but your program should compute the next four digits. Make sure your program compiles using gcc.

Then, save a text version of your program. Copy and paste the text of your program in the box here. 


/* This program computes and prints the first 6 fibonacci numbers.*/

#include<stdio.h>


int fib(int n);


int main(){

  int n = 6;

  printf("Then first %d fibonacci numbers are: \n", n);

  for(int i=1; i<=6; i++){

    int fno = fib(i);

    printf("%d\n", fno);

  }

  return 0;

}


int fib(int n){

  int fno = 0;

  if(n==1){/*The first fibonacci number is 0.*/

    fno = 0;

  }

  else if(n==2){/*The second fibonacci number is 1.*/

    fno = 1;

  }

  else{/*Recursive definition of fibonacci series.*/

    fno = fib(n-1)+fib(n-2);

  }

  return fno;

}




week 3 Assignment :


week 4 Assignment :


PROMPT

Write a program that allows the user to control the LED connected to pin 13 of the Arduino. When the program is started, the LED should be off. The user should open the serial monitor to communicate with the Arduino. If the user sends the character '1' through the serial monitor then the LED should turn on. If the user sends the character '0' through the serial monitor then the LED should turn off.

If you do not have an Arduino, you can use the web-based Arduino simulator at www.tinkercad.com. You will need to create an account for free. There are instructional videos on that website that will teach you how to use the simulator.



void setup() {

pinMode(13, OUTPUT);

Serial.begin(9600);

}

void loop() {

if (Serial.available() > 0) {

int i=Serial.read();

if(i==49){

digitalWrite(13, HIGH);

}

else if(i==48){

digitalWrite(13, LOW);

}

}

}