Notifications
Clear all

[Solved] System with two buttons for a "help system".

4 Posts
2 Users
0 Likes
1,240 Views
(@mevero)
Member
Joined: 2 years ago
Posts: 5
Topic starter  

Is it possible when you activate one of the two buttons, there start ( run) a file. ( in Micro-Python) 

The system works with Twilio, a program that sends a SMS message to a mobile phone.

The system works already but only one message is programmed.

It is for a lady who sits in a wheelchair and when she feels only she hopes her husband has time to call her. But when its urgent she pressed button two. I made it with Python and a Raspberry Pi  but when the power went down and returns you have to start the program again. The micro-controller with flash memory works always. 


   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6978
 

Here is an article I googled up on Pi autostart

https://learn.sparkfun.com/tutorials/how-to-run-a-raspberry-pi-program-on-startup/all

the bigger issue is are you running from an SD card or a USB flash drive. Power failures are a known reason for SD card failures, that is why I now only use USB flash drives.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@mevero)
Member
Joined: 2 years ago
Posts: 5
Topic starter  

Thanks for your answer, I am now interested how to make it with Micro-python.


   
ReplyQuote
(@mevero)
Member
Joined: 2 years ago
Posts: 5
Topic starter  

After a lot off looking on internet I find the solution. First a program for two buttons and the code for the file: exec(open('my file.py').read()) Part of the buttons code :

from machine import Pin

led = Pin(5, Pin.OUT)
but1 = Pin(4, Pin.IN, Pin.PULL_UP)
but2 = Pin(14, Pin.IN, Pin.PULL_UP)

def debounce(pin):
prev = None
for _ in range(32):
current_value = pin.value()
if prev != None and prev != current_value:
return None
prev = current_value
return prev

def but1_callback(pin):
d = debounce(pin)

if d == None:
return
elif not d:
led.value(not led.value())
# print('wit')
exec(open('door.py').read())

repeating this for but2


   
ReplyQuote