Modifications

Sauter à la navigation Sauter à la recherche
1 847 octets supprimés ,  11 janvier 2015 à 13:12
Ligne 231 : Ligne 231 :     
   http://shop.mchobby.be/category.php?id_category=54
 
   http://shop.mchobby.be/category.php?id_category=54
  −
This program is free software; you can redistribute it and/or modify
  −
it under the terms of the GNU General Public License as published by
  −
the Free Software Foundation; either version 2 of the License, or
  −
(at your option) any later version.
  −
 
  −
This program is distributed in the hope that it will be useful,
  −
but WITHOUT ANY WARRANTY; without even the implied warranty of
  −
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  −
GNU General Public License for more details.
  −
 
  −
You should have received a copy of the GNU General Public License
  −
along with this program; if not, write to the Free Software
  −
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  −
MA 02110-1301, USA.
  −
  −
------------------------------------------------------------------------
  −
History:
  −
  02 jan 2015 - Dominique - v 0.1 (première release)
   
"""   
 
"""   
 
from sparkapi.sparkapi import SparkApi
 
from sparkapi.sparkapi import SparkApi
Ligne 256 : Ligne 237 :  
import time
 
import time
   −
# Ouvre le fichier sparkapi.ini pour éviter de Hard Coder des données
+
# Ouvre le fichier sparkapi.ini  
# sensible comme l'access_token dans les programmes d'exemple publié sur
  −
# le Net.
  −
#
  −
# Créez votre propre fichier sparkapi.ini à partir du fichier
  −
# sparkapi-sample.ini
   
config = Config()
 
config = Config()
      
def main():
 
def main():
# Execute le programme qui récupère le nombre de pression sur
  −
#  le Spark Core.
   
api = SparkApi( access_token = config.access_token, debug = False )
 
api = SparkApi( access_token = config.access_token, debug = False )
# ou utiliser directement votre access_token
  −
#api = SparkApi( access_token = '123412341234', debug = False )
   
 
# Créer un objet Core SPECIFIQUE à partir du core_id  
+
# Créer un objet Core SPECIFIQUE pour un core_id donné
#  le core_id provient du fichier de configuration sparkapi.ini
  −
#  dans la section [CORES]
   
core = api.get_core_by_class( config.cores['core0'], SparkCoreTinker )
 
core = api.get_core_by_class( config.cores['core0'], SparkCoreTinker )
# ou utiliser directement votre core_id
  −
#core = api.get_core_by_class( '0123456789abcdef', SparkCoreTinker )
   
 
 
print( '--- Utilisation de la classe SparkCoreTinker ---' )
 
print( '--- Utilisation de la classe SparkCoreTinker ---' )
Ligne 298 : Ligne 265 :  
# eteindre la broche D0
 
# eteindre la broche D0
 
print( 'Extinction D0. digitalwrite D0 LOW = %i' % core.digitalwrite( 'D0', False ) )  
 
print( 'Extinction D0. digitalwrite D0 LOW = %i' % core.digitalwrite( 'D0', False ) )  
+
print( '--- appeler directement les fonctions Tinker ---' )
  −
# Faire une lecture en appelant directement la fonction d'API
  −
#  "digitalread" de Tinker sur le Spark Core
  −
# retourne un tuple (connected, resultat_de_la_fonction)
  −
value = core.call( 'digitalread', 'D4' )
  −
print(  'le Core n est pas connecté' if value[0] == False else 'la fonction digitalread à répondu = %i' % value[1] )
  −
time.sleep( 2 )
  −
   
return 0
 
return 0
  
29 836

modifications

Menu de navigation