Skip to main content

Posts

Showing posts with the label sound

Day 8: Intro to Data Structures | Servos and More Music

Lecture One Dimensional Arrays Arrays are a type of data structure that allows for working with a group of values using a single identifier.  Lab Servos Servos rotate to a particular angular position and stay there until told to move to a new position.  There are both standard and continuous rotation servos. Unmodified ones have a fixed range due to a potentiometer in line with the drive shaft that is used for reporting the present position. Servos are controlled by sending a pulse of a certain length; this length determines the position it will rotate to. However, in a continuous rotation servo, there is no potentiometer and the servo rotates continuously, and the pulse length determines the speed instead.  Servos draw a significant amount of current, typically more than an Arduino can supply, so it is best to use a separate power supply. Homework Hardware //Servo Potentiometer Control #include <Servo.h> const int SERVO=9; //Servo on...

Day 7: Random Numbers and Recursion | Sound

Lecture Random Numbers Random numbers can be generated using the rand function, however, the same value would be printed since it generates integers in a specified sequence. To generate a new sequence of random numbers each time, a new random-number seed is needed. First, I need to use srand to generate a seed in order for the rand function to generate new random numbers every time. We can also generate random integers between specified limits.  #include <stdio.h> #include <stdlib.h> int main(void) {   /* Declare variables and function prototype. */   unsigned int seed;   int a, b, k;   int rand_int(int a,int b);   /* Get seed value and interval limits. */   printf("Enter a positive integer seed value: \n");   scanf("%u",&seed);   srand(seed);   printf("Enter integer limits a and b (a<b): \n");   scanf("%i %i",&a,&b);   /* Generate and print ten random numbe...