<commit_before>/*
* This module allows you to control your keynote presentations using a bbc micro:bit
*
* Author: <NAME>
*
* Example:
*
* sudo node index.js
* 
*/

var BBCMicrobit = require('bbc-microbit');
var KeynoteAPI = require("./keynote");
var TimerAPI = require("./timer");

var keynote = new KeynoteAPI();
var timer = new TimerAPI();
var period = 80; // ms

console.log('Scanning for microbit...');
BBCMicrobit.discover(function(microbit) {
  console.log('Discovered microbit: %s', microbit.address);
  
  microbit.on('disconnect', function() {
    console.log('Microbit disconnected!');
    process.exit(0);
  });

  microbit.on('accelerometerChange', function(x, y, z) {
    if(timer.isValidPeriodTime()){
      xf = x.toFixed(1);
      yf = y.toFixed(1);
      zf = z.toFixed(1);
      if((xf >= -0.3 && xf <= 0.3) && (yf >= -0.2 && yf <= 0.2) ){
        if(zf == -1 ){
         console.log('Next Slide');
          keynote.startOrNext();
        }else if(zf == 1){
          console.log('Prev Slide');
          keynote.prev();
          
        } 
      } 
    }
   
    
  });

  console.log('Connecting microbit...');
  microbit.connectAndSetUp(function() {
    console.log('Status: Connected');
    console.log('Initializing...');
    microbit.writeAccelerometerPeriod(period, function() {
      console.log('Setting accelerometer...');
      microbit.subscribeAccelerometer(function() {
        console.log('Subscribed to accelerometer');
      });
    });
    console.log('Ready!');
    microbit.writeLedText('Ready!', function(){});
  });
});<commit_msg>Add support for buttons<commit_after>/*
* This module allows you to control your keynote presentations using a bbc micro:bit
*
* Author: <NAME>
*
* Example:
*
* sudo node index.js
* 
*/

var BBCMicrobit = require('bbc-microbit');
var KeynoteAPI = require("./keynote");
var TimerAPI = require("./timer");

var keynote = new KeynoteAPI();
var timer = new TimerAPI();
var period = 80; // ms

console.log('Scanning for microbit...');
BBCMicrobit.discover(function(microbit) {
  console.log('Discovered microbit: %s', microbit.address);
  
  microbit.on('disconnect', function() {
    console.log('Microbit disconnected!');
    process.exit(0);
  });

  microbit.on('accelerometerChange', function(x, y, z) {
    if(timer.isValidPeriodTime()){
      xf = x.toFixed(1);
      yf = y.toFixed(1);
      zf = z.toFixed(1);
      if((xf >= -0.3 && xf <= 0.3) && (yf >= -0.2 && yf <= 0.2) ){
        if(zf == -1 ){
          keynote.next();
        }else if(zf == 1){
          keynote.prev(); 
        } 
      } 
    }
   });

  microbit.on('buttonAChange', function(value) {
    if(value == 1) {
      console.log('Stopping presentation...');
      keynote.stop();}
  });

  microbit.on('buttonBChange', function(value) {
    if(value == 1) {
      console.log('Starting presentation...');
      keynote.start();
    }
  });

  console.log('Connecting microbit...');
  microbit.connectAndSetUp(function() {
    console.log('Status: Connected');
    console.log('Initializing...');
    microbit.subscribeButtons(function(){});
    microbit.writeAccelerometerPeriod(period, function() {
       microbit.subscribeAccelerometer(function() {});
    });
    console.log('Ready!');
    microbit.writeLedText('Ready!', function(){});
  });
});
{'fraction_non_alphanumeric': 0.18503937007874016, 'fraction_numerical': 0.01029678982434888, 'mean_word_length': 2.9795180722891565, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '386714', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1091, 'n_words': 211}