SHOW:
|
|
- or go back to the newest paste.
1 | package finch; | |
2 | import java.awt.Color; | |
3 | import edu.cmu.ri.createlab.terk.robot.finch.Finch; | |
4 | - | import java.util.Scanner; |
4 | + | |
5 | /** | |
6 | * Created by: Chris Grillo | |
7 | * Date: 11/26/2014 | |
8 | * A starter file to use the Finch | |
9 | */ | |
10 | ||
11 | public class Lightburns | |
12 | { | |
13 | Finch Matthew = new Finch(); | |
14 | private static int normal = 110; | |
15 | public static int dark = 80; | |
16 | public static int bright = 175; | |
17 | ||
18 | public static void main(final String[] args) | |
19 | { | |
20 | int SensorsAverage; | |
21 | int level=3; // Level can be 0, 1, 2 for dark, okay, bright | |
22 | ||
23 | while(true) | |
24 | { | |
25 | SensorsAverage = checkSensors(); | |
26 | level = didChange(level,SensorsAverage); | |
27 | } | |
28 | ||
29 | // Always end your program with finch.quit() | |
30 | Matthew.quit(); | |
31 | System.exit(0); | |
32 | } | |
33 | public static int checkSensors() | |
34 | { | |
35 | int SensorsAverage; | |
36 | int []lights = Matthew.getLightSensors(); | |
37 | int red=0, green=0; | |
38 | int mod = 0; | |
39 | ||
40 | lights=Matthew.getLightSensors(); | |
41 | SensorsAverage = (lights[0] + lights[1]) / 2; | |
42 | red = (int)Math.abs((normal-SensorsAverage)*2.5); | |
43 | if(red>255) | |
44 | { | |
45 | red =255; | |
46 | } | |
47 | green = 255 - red; | |
48 | Matthew.setLED(red,green,0); | |
49 | return SensorsAverage; | |
50 | } | |
51 | ||
52 | ||
53 | public static int didChange(int level, int SensorsAverage){ | |
54 | if(SensorsAverage <= dark && level != 0) // You never included and equal sign. Could be a problem | |
55 | { | |
56 | System.out.println("Its to dark and your mother is a whore"); | |
57 | level = 0; | |
58 | return level; | |
59 | } | |
60 | else if(SensorsAverage >= bright && level != 2) | |
61 | { | |
62 | System.out.print("bright as shit nigga"); | |
63 | level = 2; | |
64 | return level; | |
65 | } | |
66 | else if(level != 1) | |
67 | { | |
68 | System.out.print("alright, alright, alright"); | |
69 | level = 1; | |
70 | return level; | |
71 | } | |
72 | else | |
73 | { | |
74 | return level; | |
75 | } | |
76 | } | |
77 | } |