Skip to content

Instantly share code, notes, and snippets.

@matael
Created November 7, 2011 22:32
Show Gist options
  • Save matael/1346423 to your computer and use it in GitHub Desktop.
Save matael/1346423 to your computer and use it in GitHub Desktop.
2 digits to web
#define LATCH 7
#define DS1 8
#define DS2 10
#define SH_CP1 9
#define SH_CP2 11
const byte charset[10] = {
B10111110,//0
B00000110,//1
B01111100,//2
B01011110,//3
B11000110,//4
B11011010,//5
B11111010,//6
B00001110,//7
B11111110,//8
B11011110};//9
void setup()
{
// On initialise la liaison série
Serial.begin(9600);
pinMode(LATCH, OUTPUT);
pinMode(DS1, OUTPUT);
pinMode(DS2, OUTPUT);
pinMode(SH_CP1, OUTPUT);
pinMode(SH_CP2, OUTPUT);
}
int dizaine;
int unite;
void loop()
{
// Attention : lecture série !!!!
if (Serial.available() >=2) {
// On devrait rajouter une sécu ici : TODO
dizaine = Serial.read(); // Auto cast
unite = Serial.read(); // Auto cast
}
digitalWrite(LATCH, LOW);
shiftOut(DS1, SH_CP1, LSBFIRST, charset[int(dizaine)]);
shiftOut(DS2, SH_CP2, LSBFIRST, charset[int(unite)]);
digitalWrite(LATCH, HIGH);
}
// vim: ft=arduino ts=4 sw=4 et autoindent number
#define LATCH 7
#define DS1 8
#define DS2 10
#define SH_CP1 9
#define SH_CP2 11
const byte charset[10] = {
B10111110,//0
B00000110,//1
B01111100,//2
B01011110,//3
B11000110,//4
B11011010,//5
B11111010,//6
B00001110,//7
B11111110,//8
B11011110};//9
void setup()
{
// On initialise la liaison série
Serial.begin(9600);
pinMode(LATCH, OUTPUT);
pinMode(DS1, OUTPUT);
pinMode(DS2, OUTPUT);
pinMode(SH_CP1, OUTPUT);
pinMode(SH_CP2, OUTPUT);
}
int dizaine;
int unite;
void loop()
{
// Attention : lecture série !!!!
if (Serial.available() >=2) {
// On devrait rajouter une sécu ici : TODO
dizaine = Serial.read(); // Auto cast
unite = Serial.read(); // Auto cast
}
digitalWrite(LATCH, LOW);
shiftOut(DS1, SH_CP1, LSBFIRST, charset[dizaine-48]);
shiftOut(DS2, SH_CP2, LSBFIRST, charset[unite-48]);
digitalWrite(LATCH, HIGH);
}
// vim: ft=arduino ts=4 sw=4 et autoindent number
#-*-encoding:utf8-*-
#!/usr/bin/env python2
import sys
import os
import serial #... pour la communication série
from bottle import\ #... pour l'interface elle-même
Bottle,\
run,\
route
# On déclare l'application
app = Bottle()
# On ouvre la liaison série
serial = serial.Serial("/dev/ttyACM0", 9600)
@app.route("/:num#[0-9]{2}#")
def change_num(num):
try:
serial.write(num)
return "Done"
except: # théoriquement, on précise le type d'exception à attraper
return "fail"
def main():
# Si le programme est appellé en tant que tel (pas importé) alors on lance le serveur
run(app=app, host="localhost", port="8080")
return 0
if __name__ == '__main__': main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment