It is currently Sat Mar 25, 2017 2:39 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: FridgeBit: refrigerator door opener counter
Unread postPosted: Fri Apr 15, 2016 6:42 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 408
This probably would have made a good April Fools Day joke for you guys, but I had an old Android phone lying around
and thought I could modify my shake2text program to be sensitive enough to detect when I open my fridge if I duct tape the old phone to it
(fortunately it's an old fridge).

It sort of seems to work, but unfortunately my old phone doesn't seem to like the WakeLock command to keep it going after the screen konks out.

If I get a big chunk of time and a lot of ambition, I am thinking of making something similar using a Bluetooth Arduino board running on a 9V battery and maybe a magnetic switch. Not really sure if there is something out there similar already...



Code:
! fridgebit
! program has to be trained first
! on average jolts...
! you can move the phone around gently for a minute
! or two to fill the buffer up
!
!
!
BUNDLE.CREATE global

! graphics mode
BUNDLE.PUT global, "mode", "console"


FN.DEF dinit()

LET s$="<html><body style=\"background-color:black\"></body></html>"
HTML.CLOSE
HTML.OPEN 0
HTML.LOAD.STRING s$
BUNDLE.PUT 1,"mode","html"
FN.END


!
! change display mode to console,html or gr(aphics)
!
FN.DEF dmode(m$)
BUNDLE.GET 1,"mode",oldm$
IF oldm$=m$ THEN FN.RTN 0
BUNDLE.PUT 1,"mode",m$
IF oldm$="html" THEN HTML.CLOSE

IF oldm$="gr" THEN GR.CLOSE
IF m$="html" THEN HTML.OPEN 0

IF m$="gr" THEN GR.OPEN 255,0,0,0,0,1

IF m$="console" THEN CLS
FN.END



FN.DEF showgr(n)
dmode("gr")
GR.CLS
GR.SCREEN w,h
gr.color 255,255,255,255
GR.text.size h/3
gr.text.align 2
GR.text.draw tt, w/2,h/2,INT$(n)
GR.SHOW tt
GR.RENDER
pause 5000
FN.END

FN.DEF sendmsg(n)

FN.END


FN.DEF writeln(f$, msg$)
TEXT.OPEN w, fh, f$
TEXT.WRITELN fh, msg$
TEXT.CLOSE fh
FN.END

Fn.DEF readln$(f$)
FILE.EXISTS isoldfile, f$
IF isoldfile
  TEXT.OPEN r,fh3,f$
  TEXT.READLN fh3, a$
ELSE
  LET A$=""
ENDIF
FN.RTN a$
FN.END

dinit()
dmode("console")
TTS.INIT

Buf=0         % buffer index
Bufsiz=30      % ring buffer size
buffull=0      % true if buffer full
Noise = 0.5    % threshhold for noise
sens=0.5 % sensitivity in # of standard deviations

DIM changes[bufsiz] % ring buffer

PRINT "fridgebit"


tstart=CLOCK()
T=0

PRINT "Filling buffer..."
PRINT "Move phone around gently until Ready"
PRINT

! Open the acclerometer sensor
SENSORS.OPEN 1
SENSORS.READ 1,oldy,oldx,oldz
TIMER.SET 100

! endless loop
DO
PAUSE 50
IF jolt
  jolt=0
  eat++
   showgr(eat)
   sendmsg(eat)

  ENDIF

UNTIL 0

TIMER.CLEAR
END

ONTIMER:
SENSORS.READ 1,y,x,z
Dx = (x-oldx): Dy = (y-oldy): Dz = (z-oldz)
Change = dx*dx+dy*dy+dz*dz
IF change > noise THEN
  Buf++
  IF buf>bufsiz
   buf=1:buffull=1
  ENDIF
  Changes[buf] =change
ENDIF
Oldx=x:Oldy=y:Oldz=z


IF buffull
  IF !bflag
   PRINT "ready!"
   bflag=1
  ENDIF
  ARRAY.AVERAGE avgchange, changes[]
  ARRAY.STD_DEV sdev, changes[]

  Bigchange=avgchange
  IF change > bigchange+sdev*sens
   PRINT change
   TIME year$, month$, day$, hour$, minutes$, seconds$
   t$ = month$+"-"+day$+" "+hour$+" :"+minutes$+":"+seconds$
   PRINT t$
   jolt=1  % tell main program there is a jolt
   Bigjolts++
  ENDIF

ENDIF
TIMER.RESUME


! Set flag if screen touched
ONCONSOLETOUCH:
T=1
CONSOLETOUCH.RESUME


Report this post
Top
 Profile  
 
 Post subject: Re: FridgeBit: refrigerator door opener counter
Unread postPosted: Sat Apr 16, 2016 2:42 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 408
Actually, this version works a lot better. Just need to check if jolts are a factor bigger than the average low level noise and disable for 10 seconds each time after it trips.

Code:
! fridgebit
! program has to be trained first
! on average jolts...
! you can move the phone around gently for a minute
! or two to fill the buffer up
!
!
!
BUNDLE.CREATE global

! graphics mode
BUNDLE.PUT global, "mode", "console"


FN.DEF dinit()

LET s$="<html><body style=\"background-color:black\"></body></html>"
HTML.CLOSE
HTML.OPEN 0
HTML.LOAD.STRING s$
BUNDLE.PUT 1,"mode","html"
FN.END


!
! change display mode to console,html or gr(aphics)
!
FN.DEF dmode(m$)
BUNDLE.GET 1,"mode",oldm$
IF oldm$=m$ THEN FN.RTN 0
BUNDLE.PUT 1,"mode",m$
IF oldm$="html" THEN HTML.CLOSE

IF oldm$="gr" THEN GR.CLOSE
IF m$="html" THEN HTML.OPEN 0

IF m$="gr" THEN GR.OPEN 255,0,0,0,0,1

IF m$="console" THEN CLS
FN.END



FN.DEF showgr(n)
dmode("gr")
GR.CLS
GR.SCREEN w,h
GR.COLOR 255,255,255,255
GR.TEXT.SIZE h/3
GR.TEXT.ALIGN 2
GR.TEXT.DRAW tt, w/2,h/2,INT$(n)
GR.SHOW tt
GR.RENDER

FN.END

FN.DEF sendmsg(n)

FN.END


FN.DEF writeln(f$, msg$)
TEXT.OPEN w, fh, f$
TEXT.WRITELN fh, msg$
TEXT.CLOSE fh
fn.END

FN.DEF readln$(f$)
FILE.EXISTS isoldfile, f$
IF isoldfile
  TEXT.OPEN r,fh3,f$
  TEXT.READLN fh3, a$
ELSE
  LET A$=""
ENDIF
FN.RTN a$
FN.END

dinit()
dmode("console")
TTS.INIT

Buf=0         % buffer index
Bufsiz=30      % ring buffer size
buffull=0      % true if buffer full
Noise = 1    % threshhold for noise
sens=2 % sensitivity in # of standard deviations

DIM changes[bufsiz] % ring buffer

PRINT "fridgebit"

t=0
tstart=CLOCK()


PRINT "Filling buffer..."
PRINT "Move phone around gently until Ready"
PRINT

! Open the acclerometer sensor
SENSORS.OPEN 1
SENSORS.READ 1,oldy,oldx,oldz
TIMER.SET 100

! endless loop
DO
PAUSE 100
IF jolt
  jolt=0
  eat++
  showgr(eat)
  sendmsg(eat)
jolt=0
PAUSE 10000
jolt=0
ENDIF

UNTIL 0

TIMER.CLEAR
END

ONTIMER:
SENSORS.READ 1,y,x,z
Dx = (x-oldx): Dy = (y-oldy): Dz = (z-oldz)
Change = dx*dx+dy*dy+dz*dz
IF change > noise & !buffull
Buf++
IF buf>bufsiz
  buf=1:buffull=1
  ARRAY.AVERAGE avgchange, changes[]

ENDIF
Changes[buf] =change
ENDIF
Oldx=x:Oldy=y:Oldz=z


IF buffull
IF !bflag
  PRINT "ready!"
  bflag=1
ENDIF

IF change>avgchange*sens
  PRINT change
  TIME year$, month$, day$, hour$, minutes$, seconds$
  t$ = month$+"-"+day$+" "+hour$+" :"+minutes$+":"+seconds$
  PRINT t$
  jolt=1  % tell main program there is a jolt

ENDIF

ENDIF
TIMER.RESUME


! Set flag if screen touched
ONCONSOLETOUCH:
T=1
CONSOLETOUCH.RESUME


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred