Week 4

 Making a buzzer sound

  • Discuss max current draws on the Raspberry Pi.
    • V = IR
      For GPIO pins this means 
      3.3 = 0.016 R
      R= 3.3/0.016
      R= 206.25 Ohms
      Therefore the lowest resistance we can have in a output circuit is 206.25 Ohms
  • How to use the debugger to examine buzzer code.
  • Using the "time" calls and turning the output pin on and off make the buzzer sound
  • The buzzer sound is too low just using the GPIO pin so we need one of two things
    • A transistor to amplify the signal from the GPIO pin without increasing the current draw on the GPIO pin
    • A passive buzzer board that has a power and signal input.
  • Extension activity making the buzzer sound using PWM
  • What are the limits of changing the frequency.  Possible reasons why.

Programming today

  • Finish of variables from last week.
  • Looping For, While
    • Add up numbers 1-100 Using for loop
  • Functions (intro) 
  • Scope of blocks (counter inside function) use of the global keyword.

Homework

  • Using a while loop add Fibonacci numbers and output their values until the Fibonacci number is greater that 100,000
  • Extension homework.  Find the largest prime number you can in 1 hr. 
    RSA prime numbers used are between 1024 bits long and 2048 bits long which means they are between.... 2^1024 -1  and 2^2048 -1 
    which for a 1024 bit number the largest number would be (approx)
    179 800,000,(300 zeros) or 1.798 E 308
  •  Hints 
    • use the % (called the modulo) operator it gives you the remainder after division.
    • there is only a need to check numbers up to half plus 1 not all the numbers up to the number.
    • To test if one number equals another you have to use the equals operator which is two equals signs in a row.
      eg
       if (4 == 4):
          print(True)
    •    
    • if you get frustrated google has the answer.  Try to get frustrated first. 
    • How to run something for an hour|
      from datetime import date, datetime, timedelta
      from time import sleep
      start_time = datetime.now()
      end_time = start_time + timedelta(hours=1)
      while datetime.now() < end_time:
          print(datetime.now())
          sleep(1)


Comments

Popular posts from this blog

Github and code

Week 1