element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
element14 presents
  • Challenges & Projects
  • More
element14 presents
e14 presents blogs Bash Shell Script For Project Serling
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join element14 presents to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: airbornesurfer
  • Date Created: 26 Oct 2018 1:51 PM Date Created
  • Views 494 views
  • Likes 0 likes
  • Comments 0 comments
  • element14 presents halloween projects
  • element14 presents
  • bash
  • project serling
  • script
  • linux
Related
Recommended

Bash Shell Script For Project Serling

airbornesurfer
airbornesurfer
26 Oct 2018
image
Twilight Zone Fortune Telling Machine

element14 Presents  |  AirborneSurfer's VCP Profile |  Project Videos

 

This should be run on boot with sudo privileges.

#!/bin/bash

BUTTON=16
PWR=21
LED=5
COMMANDS=("lp -o fit-to-page 1.jpg" "lp -o fit-to-page 2.jpg" "lp -o fit-to-page 3.jpg" "lp -o fit-to-page 4.jpg" "lp -o fit-to-page 5.jpg" "lp -o fit-to-page 6.jpg" "lp -o fit-to-page 7.jpg" "lp -o fit-to-page 8.jpg" "lp -o fit-to-page 9.jpg" "lp -o fit-to-page 10.jpg" "lp -o fit-to-page 11.jpg" "lp -o fit-to-page 11.jpg" "lp -o fit-to-page 12.jpg" "lp -o fit-to-page 13.jpg" "lp -o fit-to-page 14.jpg" "lp -o fit-to-page 15.jpg" "lp -o fit-to-page 16.jpg"

# initialize serial printer serial0 at 19200 baud
stty -F /dev/serial0 19200

# initialize GPIO state
gpio -g mode $BUTTON up
gpio -g mode $PWR up
gpio -g mode $LED out

for i in `seq 1 5`;
do
        gpio -g write $LED 1
        sleep 1
        gpio -g write $LED 0
        sleep 1
done

while :
do
        # check for button press
        if [ $(gpio -g read $BUTTON) -eq 0 ]; then
                $(shuf -n1 -e "${COMMANDS[@]}")
                echo | echo | echo | lp
                #sleep 1
                # wait for user to release button before continuing
                while [ $(gpio -g read $BUTTON) -eq 0 ]; do continue; done
        fi

        # check for shutdown switch
        if [ $(gpio -g read $PWR) -eq 0 ]; then
                # Must be held for 2+ seconds before shutdown is run...
                starttime=$(date +%s)
                while [ $(gpio -g read $PWR) -eq 0 ]; do
                        if [ $(($(date +%s)-starttime)) -ge 2 ]; then
                                sudo shutdown -h                         fi
                done
        fi
done

 

Watch the Full Episode:

 

Episode 365: Twilight Zone Fortune Telling Machine

 

More Supplemental Content:

 

Project: Serling [OUTTAKES] (and an Apple rant)

 

Adobe InDesign Files For Project Serling

 

The Mystic Seer In Action

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube