narcissistic alarm clock

A place to submit all custom code, scripts, and programs.
Forum rules
Do NOT post malicious code or programs. Please review all code posted in this forum before downloading or running any of the code or programs here.

narcissistic alarm clock

Post by pretentious on Sat Jul 04, 2015 3:35 am
([msg=88786]see narcissistic alarm clock[/msg])

I have my raspberri pi set up in my bedroom and with my elementry knowledge of crontab, python and electronics, I've set up an alarm clock.

I'm a heavy sleeper, I have trouble going to sleep and have trouble getting up so I need something to really jolt my mind into its usual pretentious self, so I've hooked up a proper speaker up to my pi and have invested in a halogen bulb.

Here is my code
blink.py
Code: Select all
import time
import os
import subprocess
import RPi.GPIO as GPIO
state = ['HIGH', 'LOW']
os.system('amixer  sset PCM,0 65%')
pin = 11
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin,GPIO.OUT)
def blink(frequency):
        if frequency == 0:
            time.sleep(0.25)
            return
        #print frequency
        timeslice = frequency/4.0
        for tslice in range(int(timeslice)):
                print 'HIGH'
      GPIO.output(pin,GPIO.HIGH)
                time.sleep(0.25/timeslice)
                print 'LOW'
      GPIO.output(pin,GPIO.LOW)
                time.sleep(0.25/timeslice)

    # blink GPIO17 50 times
file = open('blink.db','r')
subprocess.Popen(['aplay',  '-q', '/home/stu/power.wav'])
for line in file.readlines():
    try:
        blink(int(line))
    except:
        if type(line) == str:
            if str(line) == "HIGH\n":
                print 'HIGH'
                GPIO.output(pin,GPIO.HIGH)
      blink(0)
            elif str(line) == "LOW\n":
                GPIO.output(pin, GPIO.LOW)
      print 'LOW'
                blink(0)
            else:
                print line
GPIO.output(pin,GPIO.LOW)
GPIO.cleanup()

blink.db
Code: Select all
LOW
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
HIGH
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
8
12
12
12
12
16
16
8
8
8
40
40
40
40
40
32
32
40
40
4
4
40
40
16
16
32
8
LOW
0
0
0
0
36
36
36
4
36
36
LOW
24
24
LOW
32
32
32
LOW
16
16
16
16
16
LOW
12
12
12
12
12
12
16
16
12
12
12
12
12
16
16
16
16
LOW
0
0
0
0
0
4
HIGH
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

power by kanye west is played through the speaker(not the greatest sound quality through the 3.5mm jack me things, and by db file is opened and a command is issued each 250ms, to turn off/on my light.
It works fine except I'm still struggling with amplifying my voltage for the bulb. The idea is that I will have the 3.5v gpio running into the gate with an external 5,10 whatever volt input going into the drain and flashing a halogen 1 meter from my face. At the moment I'm just using a LED while I figure out how to do it properly(already burnt out 2 transistors [ss]progress![/ss])
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
Can you say brainwashing It's a non stop disco
User avatar
pretentious
Addict
Addict
 
Posts: 1203
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)


Re: narcissistic alarm clock

Post by Goatboy on Sat Jul 04, 2015 4:53 pm
([msg=88851]see Re: narcissistic alarm clock[/msg])

Do not use a transistor to drive a halogen. Use a transistor to drive a relay that controls the halogen. The relay can handle much higher current and voltage, and generally does better with AC.
Assume that everything I say is or could be a lie.
User avatar
Goatboy
Expert
Expert
 
Posts: 2864
Joined: Mon Jul 07, 2008 9:35 pm
Blog: View Blog (0)


Re: narcissistic alarm clock

Post by ghost107 on Sun Jul 05, 2015 4:07 am
([msg=88854]see Re: narcissistic alarm clock[/msg])

You should try to use a level shifter(Voltage translator), if you work with 2 types of voltage.

Also try to use some resistors to pull a certain amount of amps you need, use the ohm law to compute what ohms you need for the led(if you have too much amps the LED will burn, A led works at 10mA/20mA).

For protection of your circuits of high voltage, look into Optocuplors(more precise Transistor Optocouplers and Darlington optocuplors), they are used to work with high voltage.
http://www.electronics-tutorials.ws/blo ... upler.html
User avatar
ghost107
Poster
Poster
 
Posts: 321
Joined: Wed Jul 02, 2008 7:57 am
Blog: View Blog (0)


Re: narcissistic alarm clock

Post by pretentious on Sun Jul 05, 2015 7:04 am
([msg=88855]see Re: narcissistic alarm clock[/msg])

Goatboy wrote:Do not use a transistor to drive a halogen. Use a transistor to drive a relay that controls the halogen. The relay can handle much higher current and voltage, and generally does better with AC.

Got it working with this, the ratings suggest that I need to ramp up my voltage for the relay but in practice, I could just plug pin 11 into the input and it worked.
http://imgur.com/GoTgLyI
ghost107 wrote:You should try to use a level shifter(Voltage translator), if you work with 2 types of voltage.

Also try to use some resistors to pull a certain amount of amps you need, use the ohm law to compute what ohms you need for the led(if you have too much amps the LED will burn, A led works at 10mA/20mA).

For protection of your circuits of high voltage, look into Optocuplors(more precise Transistor Optocouplers and Darlington optocuplors), they are used to work with high voltage.

I will start looking into adding more resistors and actually calculating required current for my circuits. I've been mostly about getting my hands dirty up until now and honestly I still haven't gotten my head around the relationship between V, I and R in practical terms, Mostly because Appliances have a voltage rating but not an Ampere rating, which is essentially the important one to consider :?
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
Can you say brainwashing It's a non stop disco
User avatar
pretentious
Addict
Addict
 
Posts: 1203
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)



Return to Custom Code

Who is online

Users browsing this forum: No registered users and 0 guests